[infinispan-commits] Infinispan SVN: r1338 - in trunk/server/memcached/src/main/java/org/infinispan/server: core/netty/memcached and 3 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Dec 30 14:52:31 EST 2009
Author: galder.zamarreno at jboss.com
Date: 2009-12-30 14:52:30 -0500 (Wed, 30 Dec 2009)
New Revision: 1338
Added:
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/AddCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/AppendCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CasCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CommandFactory.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CommandType.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/DecrementCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/DeleteCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/FlushAllCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/GetCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/GetsCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/IncrementCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/MemcachedStats.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/MemcachedStatsImpl.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/NumericCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/PrependCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/QuitCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/ReplaceCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/RetrievalCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/RetrievalParameters.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/SetCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StatsCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StorageCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StorageParameters.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/TextCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/TextCommandHandler.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/Value.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/VersionCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/AbstractVisitor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/CallInterceptor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/StatsInterceptor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextCommandInterceptor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextCommandInterceptorImpl.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolInterceptorChain.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolInterceptorChainFactory.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolVisitor.java
Removed:
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AbstractVisitor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AddCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AppendCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CallInterceptor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CasCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandFactory.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandType.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DecrementCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DeleteCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/FlushAllCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetsCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/IncrementCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/InterceptorChain.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStats.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStatsImpl.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/NumericCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/PrependCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/QuitCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/ReplaceCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalParameters.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/SetCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsInterceptor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageParameters.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommand.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandHandler.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptorImpl.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChain.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChainFactory.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolVisitor.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Value.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/VersionCommand.java
Modified:
trunk/server/memcached/src/main/java/org/infinispan/server/core/netty/NettyServerBootstrap.java
trunk/server/memcached/src/main/java/org/infinispan/server/core/netty/memcached/NettyMemcachedDecoder.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedTextServer.java
trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolUtil.java
Log:
[ISPN-173] (Build memcached server module) Refactor classes into more adequate packages.
Modified: trunk/server/memcached/src/main/java/org/infinispan/server/core/netty/NettyServerBootstrap.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/core/netty/NettyServerBootstrap.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/core/netty/NettyServerBootstrap.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -22,7 +22,6 @@
*/
package org.infinispan.server.core.netty;
-import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.Executors;
Modified: trunk/server/memcached/src/main/java/org/infinispan/server/core/netty/memcached/NettyMemcachedDecoder.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/core/netty/memcached/NettyMemcachedDecoder.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/core/netty/memcached/NettyMemcachedDecoder.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -34,11 +34,11 @@
import org.infinispan.Cache;
import org.infinispan.server.core.Command;
import org.infinispan.server.core.InterceptorChain;
-import org.infinispan.server.memcached.CommandFactory;
import org.infinispan.server.memcached.Reply;
-import org.infinispan.server.memcached.StorageCommand;
-import org.infinispan.server.memcached.TextCommand;
import org.infinispan.server.memcached.UnknownCommandException;
+import org.infinispan.server.memcached.commands.CommandFactory;
+import org.infinispan.server.memcached.commands.StorageCommand;
+import org.infinispan.server.memcached.commands.TextCommand;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import org.jboss.netty.buffer.ChannelBuffer;
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AbstractVisitor.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AbstractVisitor.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AbstractVisitor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,113 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * CommandInterceptor.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public abstract class AbstractVisitor implements TextProtocolVisitor {
-
- @Override
- public Object visitAdd(ChannelHandlerContext ctx, AddCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitAppend(ChannelHandlerContext ctx, AppendCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitCas(ChannelHandlerContext ctx, CasCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitDecrement(ChannelHandlerContext ctx, DecrementCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitDelete(ChannelHandlerContext ctx, DeleteCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitGet(ChannelHandlerContext ctx, GetCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitGets(ChannelHandlerContext ctx, GetsCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitIncrement(ChannelHandlerContext ctx, IncrementCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitPrepend(ChannelHandlerContext ctx, PrependCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitReplace(ChannelHandlerContext ctx, ReplaceCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitSet(ChannelHandlerContext ctx, SetCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitStats(ChannelHandlerContext ctx, StatsCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitFlushAll(ChannelHandlerContext ctx, FlushAllCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitVersion(ChannelHandlerContext ctx, VersionCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- @Override
- public Object visitQuit(ChannelHandlerContext ctx, QuitCommand command) throws Throwable {
- return handleDefault(ctx, command);
- }
-
- protected Object handleDefault(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
- return null;
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AddCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AddCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AddCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,61 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.util.concurrent.TimeUnit;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * AddCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class AddCommand extends SetCommand {
-
- AddCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
- super(cache, type, params, data);
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitAdd(ctx, this);
- }
-
- @Override
- protected Reply put(String key, int flags, byte[] data, long expiry) {
- Value value = new Value(flags, data, System.currentTimeMillis());
- Value prev = cache.putIfAbsent(key, value, expiry, TimeUnit.MILLISECONDS);
- return reply(prev);
- }
-
- private Reply reply(Value prev) {
- if (prev == null)
- return Reply.STORED;
- else
- return Reply.NOT_STORED;
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AppendCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AppendCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AppendCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,74 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * AppendCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class AppendCommand extends SetCommand {
-
- AppendCommand(Cache<String, Value> cache, StorageParameters params, byte[] data) {
- super(cache, CommandType.APPEND, params, data);
- }
-
- AppendCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
- super(cache, type, params, data);
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitAppend(ctx, this);
- }
-
- @Override
- protected Reply put(String key, int flags, byte[] data) {
- Value current = cache.get(key);
- if (current != null) {
- byte[] concatenated = concat(current.getData(), data);
- Value next = new Value(current.getFlags(), concatenated, current.getCas() + 1);
- boolean replaced = cache.replace(key, current, next);
- if (replaced)
- return Reply.STORED;
- else
- return Reply.NOT_STORED;
- } else {
- return Reply.NOT_STORED;
- }
- }
-
- protected byte[] concat(byte[] current, byte[] append) {
- return TextProtocolUtil.concat(current, append);
- }
-
- @Override
- protected Reply put(String key, int flags, byte[] data, long expiry) {
- return put(key, flags, data); // ignore expiry
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CallInterceptor.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CallInterceptor.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CallInterceptor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * CallInterceptor.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class CallInterceptor extends TextCommandInterceptorImpl {
-
- public CallInterceptor(TextCommandInterceptor next) {
- super(next);
- }
-
- @Override
- protected Object handleDefault(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
- return command.perform(ctx);
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CasCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CasCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CasCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,76 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.io.IOException;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.Command;
-
-/**
- * CasCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class CasCommand extends SetCommand {
- final long cas;
-
- CasCommand(Cache cache, StorageParameters params, long cas, byte[] data) {
- super(cache, CommandType.CAS, params, data);
- this.cas = cas;
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitCas(ctx, this);
- }
-
- @Override
- public Command setData(byte[] data) throws IOException {
- return newCasCommand(cache, params, cas, data);
- }
-
- @Override
- protected Reply put(String key, int flags, byte[] data, long expiry) {
- Value old = (Value) cache.get(key);
- if (old != null) {
- if (old.getCas() == cas) {
- Value value = new Value(flags, data, old.getCas() + 1);
- boolean replaced = cache.replace(key, old, value);
- if (replaced)
- return Reply.STORED;
- else
- return Reply.EXISTS;
- } else {
- return Reply.EXISTS;
- }
- }
- return Reply.NOT_FOUND;
- }
-
- public static CasCommand newCasCommand(Cache cache, StorageParameters params, long cas, byte[] data) {
- return new CasCommand(cache, params, cas, data);
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandFactory.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandFactory.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandFactory.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,134 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.ScheduledExecutorService;
-
-import org.infinispan.Cache;
-import org.infinispan.util.logging.Log;
-import org.infinispan.util.logging.LogFactory;
-import org.jboss.util.NotImplementedException;
-
-import org.infinispan.server.core.InterceptorChain;
-
-/**
- * CommandFactory.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class CommandFactory {
- private static final Log log = LogFactory.getLog(CommandFactory.class);
-
- private final Cache cache;
- private final InterceptorChain chain;
- private final ScheduledExecutorService scheduler;
-
- public CommandFactory(Cache cache, InterceptorChain chain, ScheduledExecutorService scheduler) {
- this.cache = cache;
- this.chain = chain;
- this.scheduler = scheduler;
- }
-
- public TextCommand createCommand(String line) throws IOException {
- if (log.isTraceEnabled()) log.trace("Command line: " + line);
- String[] args = line.trim().split(" +");
-
- CommandType type = null;
- String tmp = args[0];
- if(tmp == null)
- throw new EOFException();
- else
- type = CommandType.parseType(tmp);
-
- switch(type) {
- case SET:
- case ADD:
- case REPLACE:
- case APPEND:
- case PREPEND:
- return StorageCommand.newStorageCommand(cache, type, getStorageParameters(args), null);
- case CAS:
- tmp = args[5]; // cas unique, 64-bit integer
- long cas = Long.parseLong(tmp);
- return CasCommand.newCasCommand(cache, getStorageParameters(args), cas, null);
- case GET:
- case GETS:
- List<String> keys = new ArrayList<String>(5);
- keys.addAll(Arrays.asList(args).subList(1, args.length));
- return RetrievalCommand.newRetrievalCommand(cache, type, new RetrievalParameters(keys));
- case DELETE:
- String delKey = getKey(args[1]);
- return DeleteCommand.newDeleteCommand(cache, delKey);
- case INCR:
- case DECR:
- String key = getKey(args[1]);
- // Value is defined as unsigned 64-integer (or simply unsigned long in java language)
- // TODO: To simplify, could use long as long as the value was less than Long.MAX_VALUE
- BigInteger value = new BigInteger(args[2]);
- return NumericCommand.newNumericCommand(cache, type, key, value);
- case STATS:
- return StatsCommand.newStatsCommand(cache, type, chain);
- case FLUSH_ALL:
- long delay = args.length > 1 ? Long.parseLong(args[1]) : 0;
- return FlushAllCommand.newFlushAllCommand(cache, delay, scheduler);
- case VERSION:
- return VersionCommand.newVersionCommand();
- case QUIT:
- return QuitCommand.newQuitCommand();
- default:
- throw new NotImplementedException("Parsed type not implemented yet");
- }
- }
-
- private StorageParameters getStorageParameters(String[] args) throws IOException {
- return new StorageParameters(getKey(args[1]), getFlags(args[2]), getExpiry(args[3]), getBytes(args[4]));
- }
-
- private String getKey(String key) throws IOException {
- if (key == null) throw new EOFException();
- return key;
- }
-
- private int getFlags(String flags) throws IOException {
- if (flags == null) throw new EOFException();
- return Integer.parseInt(flags);
- }
-
- private long getExpiry(String expiry) throws IOException {
- if (expiry == null) throw new EOFException();
- return Long.parseLong(expiry); // seconds
- }
-
- private int getBytes(String bytes) throws IOException {
- if (bytes == null) throw new EOFException();
- return Integer.parseInt(bytes);
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandType.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandType.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandType.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.io.IOException;
-
-/**
- * Command.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public enum CommandType {
- SET, ADD, REPLACE, APPEND, PREPEND, CAS,
- GET, GETS,
- DELETE,
- INCR, DECR,
- STATS,
- FLUSH_ALL,
- VERSION,
- QUIT
- ;
-
- public boolean isStorage() {
- switch(this) {
- case SET:
- case ADD:
- case REPLACE:
- case APPEND:
- case PREPEND:
- case CAS:
- return true;
- default:
- return false;
- }
- }
-
- @Override
- public String toString() {
- return super.toString().toLowerCase();
- }
-
- static CommandType parseType(String type) throws IOException {
- if(type.equals(CommandType.SET.toString())) return SET;
- else if(type.equals(CommandType.ADD.toString())) return ADD;
- else if(type.equals(CommandType.REPLACE.toString())) return REPLACE;
- else if(type.equals(CommandType.APPEND.toString())) return APPEND;
- else if(type.equals(CommandType.PREPEND.toString())) return PREPEND;
- else if(type.equals(CommandType.CAS.toString())) return CAS;
- else if(type.equals(CommandType.GET.toString())) return GET;
- else if(type.equals(CommandType.GETS.toString())) return GETS;
- else if(type.equals(CommandType.DELETE.toString())) return DELETE;
- else if(type.equals(CommandType.INCR.toString())) return INCR;
- else if(type.equals(CommandType.DECR.toString())) return DECR;
- else if(type.equals(CommandType.STATS.toString())) return STATS;
- else if(type.equals(CommandType.FLUSH_ALL.toString())) return FLUSH_ALL;
- else if(type.equals(CommandType.VERSION.toString())) return VERSION;
- else if(type.equals(CommandType.QUIT.toString())) return QUIT;
- else throw new UnknownCommandException("request \"" + type + "\" not known");
- }
-
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DecrementCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DecrementCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DecrementCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,60 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.math.BigInteger;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.util.logging.Log;
-import org.infinispan.util.logging.LogFactory;
-
-/**
- * DecrementCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class DecrementCommand extends NumericCommand {
- private static final Log log = LogFactory.getLog(DecrementCommand.class);
-
- public DecrementCommand(Cache cache, CommandType type, String key, BigInteger value) {
- super(cache, type, key, value);
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitDecrement(ctx, this);
- }
-
- @Override
- protected BigInteger operate(BigInteger oldValue, BigInteger newValue) {
- if (log.isTraceEnabled()) log.trace("Substract {0} to {1}", newValue, oldValue);
- BigInteger b = oldValue.subtract(newValue);
- if (b.signum() < 0)
- return BigInteger.valueOf(0);
- else
- return b;
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DeleteCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DeleteCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DeleteCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.Channel;
-import org.infinispan.server.core.ChannelBuffers;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * DeleteCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class DeleteCommand implements TextCommand {
-
- final Cache cache;
- final String key;
-
- DeleteCommand(Cache cache, String key, long time) {
- this.cache = cache;
- this.key = key;
- }
-
- @Override
- public CommandType getType() {
- return CommandType.DELETE;
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitDelete(ctx, this);
- }
-
- @Override
- public Object perform(ChannelHandlerContext ctx) throws Throwable {
- Channel ch = ctx.getChannel();
- Reply reply;
- Object prev = cache.remove(key);
- reply = reply(prev);
- ChannelBuffers buffers = ctx.getChannelBuffers();
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(reply.bytes()), buffers.wrappedBuffer(CRLF)));
- return reply;
- }
-
- private Reply reply(Object prev) {
- if (prev == null)
- return Reply.NOT_FOUND;
- else
- return Reply.DELETED;
- }
-
- public static DeleteCommand newDeleteCommand(Cache cache, String key) {
- return new DeleteCommand(cache, key, 0);
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/FlushAllCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/FlushAllCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/FlushAllCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,94 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import static org.infinispan.server.memcached.Reply.OK;
-import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
-
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import org.infinispan.Cache;
-import org.infinispan.context.Flag;
-import org.infinispan.server.core.Channel;
-import org.infinispan.server.core.ChannelBuffers;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * FlushAllCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class FlushAllCommand implements TextCommand {
- final Cache cache;
- final long delay;
- final ScheduledExecutorService scheduler;
-
- FlushAllCommand(Cache cache, long delay, ScheduledExecutorService scheduler) {
- this.cache = cache;
- this.delay = delay;
- this.scheduler = scheduler;
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitFlushAll(ctx, this);
- }
-
- @Override
- public CommandType getType() {
- return CommandType.FLUSH_ALL;
- }
-
- @Override
- public Object perform(ChannelHandlerContext ctx) throws Throwable {
- Channel ch = ctx.getChannel();
- if (delay == 0) {
- cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_STORE).clear();
- } else {
- scheduler.schedule(new FlushAllDelayed(cache), delay, TimeUnit.SECONDS);
- }
- ChannelBuffers buffers = ctx.getChannelBuffers();
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(OK.bytes()), buffers.wrappedBuffer(CRLF)));
- return OK;
- }
-
- public static FlushAllCommand newFlushAllCommand(Cache cache, long delay, ScheduledExecutorService scheduler) {
- return new FlushAllCommand(cache, delay, scheduler);
- }
-
- private static class FlushAllDelayed implements Runnable {
- final Cache cache;
-
- FlushAllDelayed(Cache cache) {
- this.cache = cache;
- }
-
- @Override
- public void run() {
- cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_STORE).clear();
- }
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.Channel;
-import org.infinispan.server.core.ChannelBuffer;
-import org.infinispan.server.core.ChannelBuffers;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
-import static org.infinispan.server.memcached.Reply.VALUE;
-import static org.infinispan.server.memcached.Reply.END;
-
-/**
- * GetCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class GetCommand extends RetrievalCommand {
-
- GetCommand(Cache<String, Value> cache, CommandType type, RetrievalParameters params) {
- super(cache, type, params);
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitGet(ctx, this);
- }
-
- @Override
- public Object perform(ChannelHandlerContext ctx) throws Throwable {
- Channel ch = ctx.getChannel();
- ChannelBuffer buffer;
- ChannelBuffers buffers = ctx.getChannelBuffers();
- for (String key : params.keys) {
- Value value = cache.get(key);
- if (value != null) {
- StringBuilder sb = constructValue(key, value);
- buffer = buffers.wrappedBuffer(buffers.wrappedBuffer(sb.toString().getBytes()), buffers.wrappedBuffer(CRLF),
- buffers.wrappedBuffer(value.getData()), buffers.wrappedBuffer(CRLF));
- ch.write(buffer);
- }
- }
-
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(END.bytes()), buffers.wrappedBuffer(CRLF)));
- return END;
- }
-
- protected StringBuilder constructValue(String key, Value value) {
- StringBuilder sb = new StringBuilder();
- sb.append(VALUE).append(" ")
- .append(key).append(" ")
- .append(value.getFlags()).append(" ")
- .append(value.getData().length).append(" ");
- return sb;
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetsCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetsCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetsCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.Cache;
-
-/**
- * GetsCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class GetsCommand extends GetCommand {
-
- GetsCommand(Cache cache, CommandType type, RetrievalParameters params) {
- super(cache, type, params);
- }
-
- @Override
- protected StringBuilder constructValue(String key, Value value) {
- return super.constructValue(key, value).append(value.getCas()).append(" ");
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/IncrementCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/IncrementCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/IncrementCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.math.BigInteger;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.util.logging.Log;
-import org.infinispan.util.logging.LogFactory;
-
-/**
- * IncrementCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class IncrementCommand extends NumericCommand {
- private static final Log log = LogFactory.getLog(IncrementCommand.class);
-
- public IncrementCommand(Cache cache, CommandType type, String key, BigInteger value) {
- super(cache, type, key, value);
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitIncrement(ctx, this);
- }
-
- @Override
- protected BigInteger operate(BigInteger oldValue, BigInteger newValue) {
- if (log.isTraceEnabled()) log.trace("Increment {0} with {1}", oldValue, newValue);
- return oldValue.add(newValue);
- }
-
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/InterceptorChain.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/InterceptorChain.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/InterceptorChain.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.CommandInterceptor;
-
-/**
- * InterceptorChain.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class InterceptorChain {
-
- private final TextCommandInterceptor firstInChain;
-
- public InterceptorChain(TextCommandInterceptor firstInChain) {
- this.firstInChain = firstInChain;
- }
-
- public Object invoke(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
- return command.acceptVisitor(ctx, firstInChain);
- }
-
- public List<CommandInterceptor> getInterceptorsWhichExtend(Class<? extends CommandInterceptor> interceptorClass) {
- List<CommandInterceptor> result = new ArrayList<CommandInterceptor>();
- for (CommandInterceptor interceptor : asList()) {
- boolean isSubclass = interceptorClass.isAssignableFrom(interceptor.getClass());
- if (isSubclass) {
- result.add(interceptor);
- }
- }
- return result;
- }
-
- /**
- * Returns an unmofiable list with all the interceptors in sequence. If first in chain is null an empty list is
- * returned.
- */
- private List<CommandInterceptor> asList() {
- if (firstInChain == null) return Collections.emptyList();
-
- List<CommandInterceptor> retval = new LinkedList<CommandInterceptor>();
- CommandInterceptor tmp = firstInChain;
- do {
- retval.add(tmp);
- tmp = tmp.getNext();
- }
- while (tmp != null);
- return Collections.unmodifiableList(retval);
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStats.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStats.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStats.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-/**
- * MemcachedStats.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public interface MemcachedStats {
-
- long getIncrMisses();
-
- long getIncrHits();
-
- long getDecrMisses();
-
- long getDecrHits();
-
- long getCasMisses();
-
- long getCasHits();
-
- long getCasBadval();
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStatsImpl.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStatsImpl.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStatsImpl.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,138 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.util.List;
-
-import org.infinispan.stats.Stats;
-import org.infinispan.server.core.CommandInterceptor;
-import org.infinispan.server.core.InterceptorChain;
-
-/**
- * MemcachedStats.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class MemcachedStatsImpl implements MemcachedStats, Stats {
- final Stats cacheStats;
- final long incrMisses;
- final long incrHits;
- final long decrMisses;
- final long decrHits;
- final long casMisses;
- final long casHits;
- final long casBadval;
-
- MemcachedStatsImpl(Stats cacheStats, InterceptorChain chain) {
- this.cacheStats = cacheStats;
- List<CommandInterceptor> interceptors = chain.getInterceptorsWhichExtend(StatsInterceptor.class);
- if (!interceptors.isEmpty()) {
- StatsInterceptor statsInt = (StatsInterceptor) interceptors.get(0);
- incrMisses = statsInt.getIncrMisses();
- incrHits = statsInt.getIncrHits();
- decrMisses = statsInt.getDecrMisses();
- decrHits = statsInt.getDecrHits();
- casMisses = statsInt.getCasMisses();
- casHits = statsInt.getCasHits();
- casBadval = statsInt.getCasBadval();
- } else {
- incrMisses = -1;
- incrHits = -1;
- decrMisses = -1;
- decrHits = -1;
- casMisses = -1;
- casHits = -1;
- casBadval = -1;
- }
- }
-
- public long getCasBadval() {
- return casBadval;
- }
-
- public long getCasHits() {
- return casHits;
- }
-
- public long getCasMisses() {
- return casMisses;
- }
-
- public long getDecrHits() {
- return decrHits;
- }
-
- public long getDecrMisses() {
- return decrMisses;
- }
-
- public long getIncrHits() {
- return incrHits;
- }
-
- public long getIncrMisses() {
- return incrMisses;
- }
-
- public int getCurrentNumberOfEntries() {
- return cacheStats.getCurrentNumberOfEntries();
- }
-
- public long getEvictions() {
- return cacheStats.getEvictions();
- }
-
- public long getHits() {
- return cacheStats.getHits();
- }
-
- public long getMisses() {
- return cacheStats.getMisses();
- }
-
- public long getRemoveHits() {
- return cacheStats.getRemoveHits();
- }
-
- public long getRemoveMisses() {
- return cacheStats.getRemoveMisses();
- }
-
- public long getRetrievals() {
- return cacheStats.getRetrievals();
- }
-
- public long getStores() {
- return cacheStats.getStores();
- }
-
- public long getTimeSinceStart() {
- return cacheStats.getTimeSinceStart();
- }
-
- public long getTotalNumberOfEntries() {
- return cacheStats.getTotalNumberOfEntries();
- }
-
-}
Modified: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedTextServer.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedTextServer.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedTextServer.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -34,6 +34,8 @@
import org.infinispan.server.core.netty.NettyServerBootstrap;
import org.infinispan.server.core.netty.memcached.NettyMemcachedDecoder;
import org.infinispan.server.core.InterceptorChain;
+import org.infinispan.server.memcached.commands.TextCommandHandler;
+import org.infinispan.server.memcached.interceptors.TextProtocolInterceptorChainFactory;
/**
* TextServer.
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/NumericCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/NumericCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/NumericCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,95 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
-
-import java.io.IOException;
-import java.io.StreamCorruptedException;
-import java.math.BigInteger;
-
-import org.infinispan.Cache;
-import org.infinispan.CacheException;
-import org.infinispan.util.logging.Log;
-import org.infinispan.util.logging.LogFactory;
-import org.infinispan.server.core.ChannelBuffers;
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.Channel;
-
-/**
- * NumericCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public abstract class NumericCommand implements TextCommand {
- private static final Log log = LogFactory.getLog(NumericCommand.class);
- final Cache cache;
- private final CommandType type;
- final String key;
- final BigInteger value;
-
- public NumericCommand(Cache cache, CommandType type, String key, BigInteger value) {
- this.cache = cache;
- this.type = type;
- this.key = key;
- this.value = value;
- }
-
- public CommandType getType() {
- return type;
- }
-
- @Override
- public Object perform(ChannelHandlerContext ctx) throws Throwable {
- Channel ch = ctx.getChannel();
- ChannelBuffers buffers = ctx.getChannelBuffers();
- Value old = (Value) cache.get(key);
- if (old != null) {
- BigInteger oldBigInt = old.getData().length == 0 ? BigInteger.valueOf(0) : new BigInteger(old.getData());
- BigInteger newBigInt = operate(oldBigInt, value);
- byte[] newData = newBigInt.toByteArray();
- Value curr = new Value(old.getFlags(), newData, old.getCas() + 1);
- boolean replaced = cache.replace(key, old, curr);
- if (replaced) {
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(newBigInt.toString().getBytes()), buffers.wrappedBuffer(CRLF)));
- } else {
- throw new CacheException("Value modified since we retrieved from the cache, old value was " + oldBigInt);
- }
- return curr;
- } else {
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(Reply.NOT_FOUND.bytes()), buffers.wrappedBuffer(CRLF)));
- return Reply.NOT_FOUND;
- }
- }
-
- protected abstract BigInteger operate(BigInteger oldValue, BigInteger newValue);
-
- public static TextCommand newNumericCommand(Cache cache, CommandType type, String key, BigInteger value) throws IOException {
- switch(type) {
- case INCR: return new IncrementCommand(cache, type, key, value);
- case DECR: return new DecrementCommand(cache, type, key, value);
- default: throw new StreamCorruptedException("Unable to build storage command for type: " + type);
- }
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/PrependCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/PrependCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/PrependCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,50 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * PrependCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class PrependCommand extends AppendCommand {
-
- PrependCommand(Cache cache, CommandType type, StorageParameters params, byte[] data) {
- super(cache, type, params, data);
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitPrepend(ctx, this);
- }
-
- @Override
- protected byte[] concat(byte[] current, byte[] prepend) {
- return TextProtocolUtil.concat(prepend, current);
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/QuitCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/QuitCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/QuitCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.server.core.Channel;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * QuitCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public enum QuitCommand implements TextCommand {
- INSTANCE;
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitQuit(ctx, this);
- }
-
- @Override
- public CommandType getType() {
- return CommandType.QUIT;
- }
-
- @Override
- public Object perform(ChannelHandlerContext ctx) throws Throwable {
- Channel ch = ctx.getChannel();
- ch.disconnect();
- return null;
- }
-
- public static QuitCommand newQuitCommand() {
- return INSTANCE;
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/ReplaceCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/ReplaceCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/ReplaceCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.util.concurrent.TimeUnit;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * ReplaceCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class ReplaceCommand extends SetCommand {
-
- ReplaceCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
- super(cache, type, params, data);
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitReplace(ctx, this);
- }
-
- @Override
- protected Reply put(String key, int flags, byte[] data, long expiry) {
- Value old = cache.get(key);
- if (old != null) {
- Value value = new Value(flags, data, old.getCas() + 1);
- boolean replaced = cache.replace(params.key, old, value, expiry, TimeUnit.MILLISECONDS);
- return reply(replaced);
- }
- return reply(old);
- }
-
- private Reply reply(Value prev) {
- if (prev == null)
- return Reply.NOT_STORED;
- else
- return Reply.STORED;
- }
-
- private Reply reply(boolean replaced) {
- if (!replaced)
- return Reply.NOT_STORED;
- else
- return Reply.STORED;
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,56 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.Cache;
-
-/**
- * RetrievalCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public abstract class RetrievalCommand implements TextCommand {
- final Cache<String, Value> cache;
- private final CommandType type;
- final RetrievalParameters params;
-
- RetrievalCommand(Cache<String, Value> cache, CommandType type, RetrievalParameters params) {
- this.cache = cache;
- this.type = type;
- this.params = params;
- }
-
- @Override
- public CommandType getType() {
- return type;
- }
-
- public static TextCommand newRetrievalCommand(Cache<String, Value> cache, CommandType type, RetrievalParameters params) {
- switch(type) {
- case GET: return new GetCommand(cache, type, params);
- case GETS: return new GetsCommand(cache, type, params);
- default: throw new IllegalStateException("Unable to build storage command for type: " + type);
- }
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalParameters.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalParameters.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalParameters.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,39 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.util.List;
-
-/**
- * RetrievalParameters.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class RetrievalParameters {
- final List<String> keys;
-
- RetrievalParameters(List<String> keys) {
- this.keys = keys;
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/SetCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/SetCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/SetCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,124 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.util.Date;
-import java.util.concurrent.TimeUnit;
-
-import org.infinispan.Cache;
-import org.infinispan.CacheException;
-import org.infinispan.server.core.Channel;
-import org.infinispan.server.core.ChannelBuffers;
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.util.logging.Log;
-import org.infinispan.util.logging.LogFactory;
-
-import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
-
-/**
- * SetCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class SetCommand extends StorageCommand {
- private static final Log log = LogFactory.getLog(SetCommand.class);
-
- SetCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
- super(cache, type, params, data);
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitSet(ctx, this);
- }
-
- @Override
- public Object perform(ChannelHandlerContext ctx) throws Exception {
- Channel ch = ctx.getChannel();
- Reply reply;
- try {
- if (params.expiry == 0) {
- reply = put(params.key, params.flags, data);
- } else {
- if (params.expiry > TextProtocolUtil.SECONDS_IN_A_MONTH) {
- // If expiry bigger number of seconds in 30 days, then it's considered unix time
- long future = TimeUnit.SECONDS.toMillis(params.expiry);
- long expiry = future - System.currentTimeMillis();
- if (expiry > 0) {
- reply = put(params.key, params.flags, data, expiry);
- } else {
- StringBuilder sb = new StringBuilder();
- sb.append("Given expiry is bigger than 30 days, hence is treated as Unix time, ")
- .append("but this time is in the past: ").append(future)
- .append(", date: ").append(new Date(future));
- throw new CacheException(sb.toString());
- }
- } else {
- // Convert seconds to milliseconds to simplify code
- long expiry = TimeUnit.SECONDS.toMillis(params.expiry);
- reply = put(params.key, params.flags, data, expiry);
- }
- }
-
- } catch (Exception e) {
- log.error("Unexpected exception performing command", e);
- reply = Reply.NOT_STORED;
- }
- ChannelBuffers buffers = ctx.getChannelBuffers();
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(reply.bytes()), buffers.wrappedBuffer(CRLF)));
- return reply;
- }
-
- protected Reply put(String key, int flags, byte[] data) {
- return put(key, flags, data, -1);
- }
-
- protected Reply put(String key, int flags, byte[] data, long expiry) {
- Value prev = cache.get(key);
- Value value;
- if (prev != null) {
- value = new Value(flags, data, prev.getCas() + 1);
- boolean replaced = cache.replace(key, prev, value, expiry, TimeUnit.MILLISECONDS);
- return reply(replaced);
- } else {
- value = new Value(flags, data, System.currentTimeMillis());
- prev = cache.putIfAbsent(key, value, expiry, TimeUnit.MILLISECONDS);
- return reply(prev);
- }
- }
-
- private Reply reply(boolean replaced) {
- if (!replaced)
- return Reply.NOT_STORED;
- else
- return Reply.STORED;
- }
-
- private Reply reply(Value prev) {
- if (prev == null)
- return Reply.STORED;
- else
- return Reply.NOT_STORED;
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,125 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import static org.infinispan.server.memcached.Reply.END;
-import static org.infinispan.server.memcached.Reply.STAT;
-import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
-
-import java.util.concurrent.TimeUnit;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.Channel;
-import org.infinispan.server.core.ChannelBuffers;
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.InterceptorChain;
-
-/**
- * StatsCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class StatsCommand implements TextCommand {
- final Cache cache;
- private final CommandType type;
- final InterceptorChain chain;
-
- StatsCommand(Cache cache, CommandType type, InterceptorChain chain) {
- this.cache = cache;
- this.type = type;
- this.chain = chain;
- }
-
- @Override
- public CommandType getType() {
- return CommandType.STATS;
- }
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitStats(ctx, this);
- }
-
- @Override
- public Object perform(ChannelHandlerContext ctx) throws Throwable {
- MemcachedStatsImpl stats = new MemcachedStatsImpl(cache.getAdvancedCache().getStats(), chain);
-
- StringBuilder sb = new StringBuilder();
- writeStat("pid", 0, sb, ctx); // Unsupported
- writeStat("uptime", stats.getTimeSinceStart(), sb, ctx);
- writeStat("time", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()), sb, ctx);
- writeStat("version", cache.getVersion(), sb, ctx);
- writeStat("pointer_size", 0, sb, ctx); // Unsupported
- writeStat("rusage_user", 0, sb, ctx); // Unsupported
- writeStat("rusage_system", 0, sb, ctx); // Unsupported
- writeStat("curr_items", stats.getCurrentNumberOfEntries(), sb, ctx);
- writeStat("total_items", stats.getTotalNumberOfEntries(), sb, ctx);
- writeStat("bytes", 0, sb, ctx); // Unsupported
- writeStat("curr_connections", 0, sb, ctx); // TODO: Through netty?
- writeStat("total_connections", 0, sb, ctx); // TODO: Through netty?
- writeStat("connection_structures", 0, sb, ctx); // Unsupported
- writeStat("cmd_get", stats.getRetrievals(), sb, ctx);
- writeStat("cmd_set", stats.getStores(), sb, ctx);
- writeStat("get_hits", stats.getHits(), sb, ctx);
- writeStat("get_misses", stats.getMisses(), sb, ctx);
- writeStat("delete_misses", stats.getRemoveMisses(), sb, ctx);
- writeStat("delete_hits", stats.getRemoveHits(), sb, ctx);
- writeStat("incr_misses", stats.getIncrMisses(), sb, ctx);
- writeStat("incr_hits", stats.getIncrHits(), sb, ctx);
- writeStat("decr_misses", stats.getDecrMisses(), sb, ctx);
- writeStat("decr_hits", stats.getDecrHits(), sb, ctx);
- writeStat("cas_misses", stats.getCasMisses(), sb, ctx);
- writeStat("cas_hits", stats.getCasHits(), sb, ctx);
- writeStat("cas_badval", stats.getCasBadval(), sb, ctx);
- writeStat("auth_cmds", 0, sb, ctx); // Unsupported
- writeStat("auth_errors", 0, sb, ctx); // Unsupported
- //TODO: Evictions are measure by evict calls, but not by nodes are that
- // are expired after the entry's lifespan has expired.
- writeStat("evictions", stats.getEvictions(), sb, ctx);
- writeStat("bytes_read", 0, sb, ctx); // TODO: Through netty?
- writeStat("bytes_written", 0, sb, ctx); // TODO: Through netty?
- writeStat("limit_maxbytes", 0, sb, ctx); // Unsupported
- writeStat("threads", 0, sb, ctx); // TODO: Through netty?
- writeStat("conn_yields", 0, sb, ctx); // Unsupported
-
- ChannelBuffers buffers = ctx.getChannelBuffers();
- Channel ch = ctx.getChannel();
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(END.bytes()), buffers.wrappedBuffer(CRLF)));
-
- return END;
- }
-
- private void writeStat(String stat, Object value, StringBuilder sb, ChannelHandlerContext ctx) {
- ChannelBuffers buffers = ctx.getChannelBuffers();
- Channel ch = ctx.getChannel();
- sb.append(STAT).append(' ').append(stat).append(' ').append(value);
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(sb.toString().getBytes()), buffers.wrappedBuffer(CRLF)));
- sb.setLength(0);
- }
-
- public static TextCommand newStatsCommand(Cache cache, CommandType type, InterceptorChain chain) {
- return new StatsCommand(cache, type, chain);
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsInterceptor.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsInterceptor.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsInterceptor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,120 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * StatsInterceptor.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class StatsInterceptor extends TextCommandInterceptorImpl implements MemcachedStats {
- private final AtomicLong incrMisses = new AtomicLong(0);
- private final AtomicLong incrHits = new AtomicLong(0);
- private final AtomicLong decrMisses = new AtomicLong(0);
- private final AtomicLong decrHits = new AtomicLong(0);
- private final AtomicLong casMisses = new AtomicLong(0);
- private final AtomicLong casHits = new AtomicLong(0);
- private final AtomicLong casBadval = new AtomicLong(0);
-
- public StatsInterceptor(TextCommandInterceptor next) {
- super(next);
- }
-
- @Override
- public Object visitIncrement(ChannelHandlerContext ctx, IncrementCommand command) throws Throwable {
- Object ret = invokeNextInterceptor(ctx, command);
- if (ret != Reply.NOT_FOUND)
- incrHits.incrementAndGet();
- else
- incrMisses.incrementAndGet();
- return ret;
- }
-
- @Override
- public Object visitDecrement(ChannelHandlerContext ctx, DecrementCommand command) throws Throwable {
- Object ret = invokeNextInterceptor(ctx, command);
- if (ret != Reply.NOT_FOUND)
- decrHits.incrementAndGet();
- else
- decrMisses.incrementAndGet();
- return ret;
- }
-
- @Override
- public Object visitCas(ChannelHandlerContext ctx, CasCommand command) throws Throwable {
- Reply ret = (Reply) invokeNextInterceptor(ctx, command);
- switch (ret) {
- case STORED:
- casHits.incrementAndGet();
- break;
- case NOT_FOUND:
- casMisses.incrementAndGet();
- break;
- case EXISTS:
- casBadval.incrementAndGet();
- break;
- }
- return ret;
- }
-
- @Override
- public long getIncrHits() {
- return incrHits.get();
- }
-
- @Override
- public long getIncrMisses() {
- return incrMisses.get();
- }
-
- @Override
- public long getDecrHits() {
- return decrHits.get();
- }
-
- @Override
- public long getDecrMisses() {
- return decrMisses.get();
- }
-
- @Override
- public long getCasBadval() {
- return casBadval.get();
- }
-
- @Override
- public long getCasHits() {
- return casHits.get();
- }
-
- @Override
- public long getCasMisses() {
- return casMisses.get();
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.io.IOException;
-import java.io.StreamCorruptedException;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.Command;
-
-/**
- * StorageCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public abstract class StorageCommand implements TextCommand {
- private final CommandType type;
- final Cache<String, Value> cache;
- final StorageParameters params;
- final byte[] data;
-
- StorageCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
- this.type = type;
- this.params = params;
- this.cache = cache;
- this.data = data;
- }
-
- public CommandType getType() {
- return type;
- }
-
- public Command setData(byte[] data) throws IOException {
- return newStorageCommand(cache, type, params, data);
- }
-
- public StorageParameters getParams() {
- return params;
- }
-
- public static TextCommand newStorageCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) throws IOException {
- switch(type) {
- case SET: return new SetCommand(cache, type, params, data);
- case ADD: return new AddCommand(cache, type, params, data);
- case REPLACE: return new ReplaceCommand(cache, type, params, data);
- case APPEND: return new AppendCommand(cache, type, params, data);
- case PREPEND: return new PrependCommand(cache, type, params, data);
- default: throw new StreamCorruptedException("Unable to build storage command for type: " + type);
- }
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageParameters.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageParameters.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageParameters.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-/**
- * StorageParameters.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class StorageParameters {
- final String key;
- final int flags;
- final long expiry;
- final int bytes;
- boolean noreply;
-
- StorageParameters(String key, int flags, long expiry, int bytes) {
- this.key = key;
- this.flags = flags;
- this.expiry = expiry;
- this.bytes = bytes;
- }
-
- public int getBytes() {
- return bytes;
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.Command;
-
-/**
- * TextCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public interface TextCommand extends Command {
- Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable;
- CommandType getType();
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandHandler.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandHandler.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandHandler.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.CommandHandler;
-import org.infinispan.server.core.MessageEvent;
-import org.infinispan.server.core.InterceptorChain;
-
-/**
- * TextProtocolServerHandler.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-class TextCommandHandler implements CommandHandler {
- final Cache cache;
- final InterceptorChain chain;
-
- public TextCommandHandler(Cache cache, InterceptorChain chain) {
- this.cache = cache;
- this.chain = chain;
- }
-
- @Override
- public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Throwable {
- chain.invoke(ctx, (TextCommand) e.getMessage());
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptor.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptor.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.CommandInterceptor;
-
-/**
- * TextCommandInterceptor.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public interface TextCommandInterceptor extends CommandInterceptor, TextProtocolVisitor {
- Object invokeNextInterceptor(ChannelHandlerContext ctx, TextCommand command) throws Throwable;
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptorImpl.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptorImpl.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptorImpl.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,56 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.CommandInterceptor;
-
-/**
- * TextCommandInterceptorImpl.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class TextCommandInterceptorImpl extends AbstractVisitor implements TextCommandInterceptor {
- private final TextCommandInterceptor next;
-
- TextCommandInterceptorImpl(TextCommandInterceptor next) {
- this.next = next;
- }
-
- @Override
- public Object invokeNextInterceptor(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
- return command.acceptVisitor(ctx, next);
- }
-
- @Override
- public CommandInterceptor getNext() {
- return next;
- }
-
- @Override
- protected Object handleDefault(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
- return invokeNextInterceptor(ctx, command);
- }
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChain.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChain.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChain.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-import org.infinispan.server.core.Command;
-import org.infinispan.server.core.CommandInterceptor;
-import org.infinispan.server.core.InterceptorChain;
-
-/**
- * TextProtocolInterceptorChain.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public class TextProtocolInterceptorChain implements InterceptorChain {
-
- private final TextCommandInterceptor firstInChain;
-
- public TextProtocolInterceptorChain(TextCommandInterceptor firstInChain) {
- this.firstInChain = firstInChain;
- }
-
- @Override
- public Object invoke(ChannelHandlerContext ctx, Command command) throws Throwable {
- return ((TextCommand) command).acceptVisitor(ctx, firstInChain);
- }
-
- public List<CommandInterceptor> getInterceptorsWhichExtend(Class<? extends CommandInterceptor> interceptorClass) {
- List<CommandInterceptor> result = new ArrayList<CommandInterceptor>();
- for (CommandInterceptor interceptor : asList()) {
- boolean isSubclass = interceptorClass.isAssignableFrom(interceptor.getClass());
- if (isSubclass) {
- result.add(interceptor);
- }
- }
- return result;
- }
-
- /**
- * Returns an unmofiable list with all the interceptors in sequence. If first in chain is null an empty list is
- * returned.
- */
- private List<CommandInterceptor> asList() {
- if (firstInChain == null) return Collections.emptyList();
-
- List<CommandInterceptor> retval = new LinkedList<CommandInterceptor>();
- CommandInterceptor tmp = firstInChain;
- do {
- retval.add(tmp);
- tmp = tmp.getNext();
- }
- while (tmp != null);
- return Collections.unmodifiableList(retval);
- }
-
-
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChainFactory.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChainFactory.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChainFactory.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,61 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.Cache;
-import org.infinispan.server.core.InterceptorChainFactory;
-import org.infinispan.server.core.InterceptorChain;
-
-/**
- * InterceptorChainFactory.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public enum TextProtocolInterceptorChainFactory implements InterceptorChainFactory {
- STATS_ENABLED(true), NOT_STATS_ENABLED(false);
-
- private final boolean statsEnabled;
-
- private TextProtocolInterceptorChainFactory(boolean statsEnabled) {
- this.statsEnabled = statsEnabled;
- }
-
- public InterceptorChain buildInterceptorChain() {
- TextCommandInterceptor first;
- if (statsEnabled) {
- first = new StatsInterceptor(new CallInterceptor(null));
- } else {
- first = new CallInterceptor(null);
- }
-
- return new TextProtocolInterceptorChain(first);
- }
-
- public static TextProtocolInterceptorChainFactory getInstance(Cache cache) {
- if (cache.getConfiguration().isExposeJmxStatistics())
- return STATS_ENABLED;
- else
- return NOT_STATS_ENABLED;
- }
-}
Modified: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolUtil.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolUtil.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolUtil.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -32,7 +32,7 @@
public static final byte CR = 13;
public static final byte LF = 10;
public static final byte[] CRLF = new byte[] { CR, LF };
- static final long SECONDS_IN_A_MONTH = 60*60*24*30;
+ public static final long SECONDS_IN_A_MONTH = 60*60*24*30;
public static byte[] concat(byte[] a, byte[] b) {
byte[] data = new byte[a.length + b.length];
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolVisitor.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolVisitor.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolVisitor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,49 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import org.infinispan.server.core.ChannelHandlerContext;
-
-/**
- * CommandInterceptor.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public interface TextProtocolVisitor {
- Object visitSet(ChannelHandlerContext ctx, SetCommand command) throws Throwable;
- Object visitAdd(ChannelHandlerContext ctx, AddCommand command) throws Throwable;
- Object visitReplace(ChannelHandlerContext ctx, ReplaceCommand command) throws Throwable;
- Object visitAppend(ChannelHandlerContext ctx, AppendCommand command) throws Throwable;
- Object visitPrepend(ChannelHandlerContext ctx, PrependCommand command) throws Throwable;
- Object visitCas(ChannelHandlerContext ctx, CasCommand command) throws Throwable;
- Object visitGet(ChannelHandlerContext ctx, GetCommand command) throws Throwable;
- Object visitGets(ChannelHandlerContext ctx, GetsCommand command) throws Throwable;
- Object visitDelete(ChannelHandlerContext ctx, DeleteCommand command) throws Throwable;
- Object visitIncrement(ChannelHandlerContext ctx, IncrementCommand command) throws Throwable;
- Object visitDecrement(ChannelHandlerContext ctx, DecrementCommand command) throws Throwable;
- Object visitStats(ChannelHandlerContext ctx, StatsCommand command) throws Throwable;
- Object visitFlushAll(ChannelHandlerContext ctx, FlushAllCommand command) throws Throwable;
- Object visitVersion(ChannelHandlerContext ctx, VersionCommand command) throws Throwable;
- Object visitQuit(ChannelHandlerContext ctx, QuitCommand command) throws Throwable;
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Value.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Value.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Value.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,105 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-
-/**
- * Value.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-class Value implements Externalizable {
- private int flags;
- private byte[] data;
- private long cas;
-
- Value(int flags, byte[] data, long cas) {
- this.flags = flags;
- this.data = data;
- this.cas = cas;
- }
-
- public int getFlags() {
- return flags;
- }
-
- public byte[] getData() {
- return data;
- }
-
- public long getCas() {
- return cas;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (!(obj instanceof Value))
- return false;
- Value other = (Value) obj;
- return Arrays.equals(data, other.data)
- && flags == other.flags
- && cas == other.cas;
- }
-
- @Override
- public int hashCode() {
- int result = 17;
- result = 31 * result + flags;
- result = 31 * result + data.hashCode();
- result = 31 * result + (int)(cas ^ (cas >>> 32));
- return result;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "data=" + Arrays.toString(data) +
- ", flags=" + flags +
- ", cas=" + cas +
- "}";
- }
-
- @Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- flags = in.read();
- data = new byte[in.read()];
- in.read(data);
- cas = in.readLong();
- }
-
- @Override
- public void writeExternal(ObjectOutput out) throws IOException {
- out.write(flags);
- out.write(data.length);
- out.write(data);
- out.writeLong(cas);
- }
-}
Deleted: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/VersionCommand.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/VersionCommand.java 2009-12-30 17:58:15 UTC (rev 1337)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/VersionCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -1,66 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.memcached;
-
-import static org.infinispan.server.memcached.Reply.VERSION;
-
-import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
-
-import org.infinispan.Version;
-import org.infinispan.server.core.Channel;
-import org.infinispan.server.core.ChannelBuffers;
-import org.infinispan.server.core.ChannelHandlerContext;
-
-
-/**
- * VersionCommand.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
-public enum VersionCommand implements TextCommand {
- INSTANCE;
-
- @Override
- public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
- return next.visitVersion(ctx, this);
- }
-
- @Override
- public CommandType getType() {
- return CommandType.VERSION;
- }
-
- @Override
- public Object perform(ChannelHandlerContext ctx) throws Exception {
- Channel ch = ctx.getChannel();
- String version = ' ' + Version.version;
- ChannelBuffers buffers = ctx.getChannelBuffers();
- ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(VERSION.bytes()), buffers.wrappedBuffer(version.getBytes()), buffers.wrappedBuffer(CRLF)));
- return VERSION;
- }
-
- public static VersionCommand newVersionCommand() {
- return INSTANCE;
- }
-}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/AddCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AddCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/AddCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/AddCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.util.concurrent.TimeUnit;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.Reply;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * AddCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class AddCommand extends SetCommand {
+
+ AddCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
+ super(cache, type, params, data);
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitAdd(ctx, this);
+ }
+
+ @Override
+ protected Reply put(String key, int flags, byte[] data, long expiry) {
+ Value value = new Value(flags, data, System.currentTimeMillis());
+ Value prev = cache.putIfAbsent(key, value, expiry, TimeUnit.MILLISECONDS);
+ return reply(prev);
+ }
+
+ private Reply reply(Value prev) {
+ if (prev == null)
+ return Reply.STORED;
+ else
+ return Reply.NOT_STORED;
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/AppendCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AppendCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/AppendCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/AppendCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.Reply;
+import org.infinispan.server.memcached.TextProtocolUtil;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * AppendCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class AppendCommand extends SetCommand {
+
+ AppendCommand(Cache<String, Value> cache, StorageParameters params, byte[] data) {
+ super(cache, CommandType.APPEND, params, data);
+ }
+
+ AppendCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
+ super(cache, type, params, data);
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitAppend(ctx, this);
+ }
+
+ @Override
+ protected Reply put(String key, int flags, byte[] data) {
+ Value current = cache.get(key);
+ if (current != null) {
+ byte[] concatenated = concat(current.getData(), data);
+ Value next = new Value(current.getFlags(), concatenated, current.getCas() + 1);
+ boolean replaced = cache.replace(key, current, next);
+ if (replaced)
+ return Reply.STORED;
+ else
+ return Reply.NOT_STORED;
+ } else {
+ return Reply.NOT_STORED;
+ }
+ }
+
+ protected byte[] concat(byte[] current, byte[] append) {
+ return TextProtocolUtil.concat(current, append);
+ }
+
+ @Override
+ protected Reply put(String key, int flags, byte[] data, long expiry) {
+ return put(key, flags, data); // ignore expiry
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CasCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CasCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CasCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CasCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.io.IOException;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.core.Command;
+import org.infinispan.server.memcached.Reply;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * CasCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class CasCommand extends SetCommand {
+ final long cas;
+
+ CasCommand(Cache cache, StorageParameters params, long cas, byte[] data) {
+ super(cache, CommandType.CAS, params, data);
+ this.cas = cas;
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitCas(ctx, this);
+ }
+
+ @Override
+ public Command setData(byte[] data) throws IOException {
+ return newCasCommand(cache, params, cas, data);
+ }
+
+ @Override
+ protected Reply put(String key, int flags, byte[] data, long expiry) {
+ Value old = (Value) cache.get(key);
+ if (old != null) {
+ if (old.getCas() == cas) {
+ Value value = new Value(flags, data, old.getCas() + 1);
+ boolean replaced = cache.replace(key, old, value);
+ if (replaced)
+ return Reply.STORED;
+ else
+ return Reply.EXISTS;
+ } else {
+ return Reply.EXISTS;
+ }
+ }
+ return Reply.NOT_FOUND;
+ }
+
+ public static CasCommand newCasCommand(Cache cache, StorageParameters params, long cas, byte[] data) {
+ return new CasCommand(cache, params, cas, data);
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CommandFactory.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandFactory.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CommandFactory.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CommandFactory.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,134 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.infinispan.Cache;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.jboss.util.NotImplementedException;
+
+import org.infinispan.server.core.InterceptorChain;
+
+/**
+ * CommandFactory.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class CommandFactory {
+ private static final Log log = LogFactory.getLog(CommandFactory.class);
+
+ private final Cache cache;
+ private final InterceptorChain chain;
+ private final ScheduledExecutorService scheduler;
+
+ public CommandFactory(Cache cache, InterceptorChain chain, ScheduledExecutorService scheduler) {
+ this.cache = cache;
+ this.chain = chain;
+ this.scheduler = scheduler;
+ }
+
+ public TextCommand createCommand(String line) throws IOException {
+ if (log.isTraceEnabled()) log.trace("Command line: " + line);
+ String[] args = line.trim().split(" +");
+
+ CommandType type = null;
+ String tmp = args[0];
+ if(tmp == null)
+ throw new EOFException();
+ else
+ type = CommandType.parseType(tmp);
+
+ switch(type) {
+ case SET:
+ case ADD:
+ case REPLACE:
+ case APPEND:
+ case PREPEND:
+ return StorageCommand.newStorageCommand(cache, type, getStorageParameters(args), null);
+ case CAS:
+ tmp = args[5]; // cas unique, 64-bit integer
+ long cas = Long.parseLong(tmp);
+ return CasCommand.newCasCommand(cache, getStorageParameters(args), cas, null);
+ case GET:
+ case GETS:
+ List<String> keys = new ArrayList<String>(5);
+ keys.addAll(Arrays.asList(args).subList(1, args.length));
+ return RetrievalCommand.newRetrievalCommand(cache, type, new RetrievalParameters(keys));
+ case DELETE:
+ String delKey = getKey(args[1]);
+ return DeleteCommand.newDeleteCommand(cache, delKey);
+ case INCR:
+ case DECR:
+ String key = getKey(args[1]);
+ // Value is defined as unsigned 64-integer (or simply unsigned long in java language)
+ // TODO: To simplify, could use long as long as the value was less than Long.MAX_VALUE
+ BigInteger value = new BigInteger(args[2]);
+ return NumericCommand.newNumericCommand(cache, type, key, value);
+ case STATS:
+ return StatsCommand.newStatsCommand(cache, type, chain);
+ case FLUSH_ALL:
+ long delay = args.length > 1 ? Long.parseLong(args[1]) : 0;
+ return FlushAllCommand.newFlushAllCommand(cache, delay, scheduler);
+ case VERSION:
+ return VersionCommand.newVersionCommand();
+ case QUIT:
+ return QuitCommand.newQuitCommand();
+ default:
+ throw new NotImplementedException("Parsed type not implemented yet");
+ }
+ }
+
+ private StorageParameters getStorageParameters(String[] args) throws IOException {
+ return new StorageParameters(getKey(args[1]), getFlags(args[2]), getExpiry(args[3]), getBytes(args[4]));
+ }
+
+ private String getKey(String key) throws IOException {
+ if (key == null) throw new EOFException();
+ return key;
+ }
+
+ private int getFlags(String flags) throws IOException {
+ if (flags == null) throw new EOFException();
+ return Integer.parseInt(flags);
+ }
+
+ private long getExpiry(String expiry) throws IOException {
+ if (expiry == null) throw new EOFException();
+ return Long.parseLong(expiry); // seconds
+ }
+
+ private int getBytes(String bytes) throws IOException {
+ if (bytes == null) throw new EOFException();
+ return Integer.parseInt(bytes);
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CommandType.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CommandType.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CommandType.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/CommandType.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.io.IOException;
+
+import org.infinispan.server.memcached.UnknownCommandException;
+
+/**
+ * Command.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public enum CommandType {
+ SET, ADD, REPLACE, APPEND, PREPEND, CAS,
+ GET, GETS,
+ DELETE,
+ INCR, DECR,
+ STATS,
+ FLUSH_ALL,
+ VERSION,
+ QUIT
+ ;
+
+ public boolean isStorage() {
+ switch(this) {
+ case SET:
+ case ADD:
+ case REPLACE:
+ case APPEND:
+ case PREPEND:
+ case CAS:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return super.toString().toLowerCase();
+ }
+
+ static CommandType parseType(String type) throws IOException {
+ if(type.equals(CommandType.SET.toString())) return SET;
+ else if(type.equals(CommandType.ADD.toString())) return ADD;
+ else if(type.equals(CommandType.REPLACE.toString())) return REPLACE;
+ else if(type.equals(CommandType.APPEND.toString())) return APPEND;
+ else if(type.equals(CommandType.PREPEND.toString())) return PREPEND;
+ else if(type.equals(CommandType.CAS.toString())) return CAS;
+ else if(type.equals(CommandType.GET.toString())) return GET;
+ else if(type.equals(CommandType.GETS.toString())) return GETS;
+ else if(type.equals(CommandType.DELETE.toString())) return DELETE;
+ else if(type.equals(CommandType.INCR.toString())) return INCR;
+ else if(type.equals(CommandType.DECR.toString())) return DECR;
+ else if(type.equals(CommandType.STATS.toString())) return STATS;
+ else if(type.equals(CommandType.FLUSH_ALL.toString())) return FLUSH_ALL;
+ else if(type.equals(CommandType.VERSION.toString())) return VERSION;
+ else if(type.equals(CommandType.QUIT.toString())) return QUIT;
+ else throw new UnknownCommandException("request \"" + type + "\" not known");
+ }
+
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/DecrementCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DecrementCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/DecrementCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/DecrementCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.math.BigInteger;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
+/**
+ * DecrementCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class DecrementCommand extends NumericCommand {
+ private static final Log log = LogFactory.getLog(DecrementCommand.class);
+
+ public DecrementCommand(Cache cache, CommandType type, String key, BigInteger value) {
+ super(cache, type, key, value);
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitDecrement(ctx, this);
+ }
+
+ @Override
+ protected BigInteger operate(BigInteger oldValue, BigInteger newValue) {
+ if (log.isTraceEnabled()) log.trace("Substract {0} to {1}", newValue, oldValue);
+ BigInteger b = oldValue.subtract(newValue);
+ if (b.signum() < 0)
+ return BigInteger.valueOf(0);
+ else
+ return b;
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/DeleteCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/DeleteCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/DeleteCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/DeleteCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.Channel;
+import org.infinispan.server.core.ChannelBuffers;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.Reply;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * DeleteCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class DeleteCommand implements TextCommand {
+
+ final Cache cache;
+ final String key;
+
+ DeleteCommand(Cache cache, String key, long time) {
+ this.cache = cache;
+ this.key = key;
+ }
+
+ @Override
+ public CommandType getType() {
+ return CommandType.DELETE;
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitDelete(ctx, this);
+ }
+
+ @Override
+ public Object perform(ChannelHandlerContext ctx) throws Throwable {
+ Channel ch = ctx.getChannel();
+ Reply reply;
+ Object prev = cache.remove(key);
+ reply = reply(prev);
+ ChannelBuffers buffers = ctx.getChannelBuffers();
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(reply.bytes()), buffers.wrappedBuffer(CRLF)));
+ return reply;
+ }
+
+ private Reply reply(Object prev) {
+ if (prev == null)
+ return Reply.NOT_FOUND;
+ else
+ return Reply.DELETED;
+ }
+
+ public static DeleteCommand newDeleteCommand(Cache cache, String key) {
+ return new DeleteCommand(cache, key, 0);
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/FlushAllCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/FlushAllCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/FlushAllCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/FlushAllCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import static org.infinispan.server.memcached.Reply.OK;
+import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
+
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.infinispan.Cache;
+import org.infinispan.context.Flag;
+import org.infinispan.server.core.Channel;
+import org.infinispan.server.core.ChannelBuffers;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * FlushAllCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class FlushAllCommand implements TextCommand {
+ final Cache cache;
+ final long delay;
+ final ScheduledExecutorService scheduler;
+
+ FlushAllCommand(Cache cache, long delay, ScheduledExecutorService scheduler) {
+ this.cache = cache;
+ this.delay = delay;
+ this.scheduler = scheduler;
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitFlushAll(ctx, this);
+ }
+
+ @Override
+ public CommandType getType() {
+ return CommandType.FLUSH_ALL;
+ }
+
+ @Override
+ public Object perform(ChannelHandlerContext ctx) throws Throwable {
+ Channel ch = ctx.getChannel();
+ if (delay == 0) {
+ cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_STORE).clear();
+ } else {
+ scheduler.schedule(new FlushAllDelayed(cache), delay, TimeUnit.SECONDS);
+ }
+ ChannelBuffers buffers = ctx.getChannelBuffers();
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(OK.bytes()), buffers.wrappedBuffer(CRLF)));
+ return OK;
+ }
+
+ public static FlushAllCommand newFlushAllCommand(Cache cache, long delay, ScheduledExecutorService scheduler) {
+ return new FlushAllCommand(cache, delay, scheduler);
+ }
+
+ private static class FlushAllDelayed implements Runnable {
+ final Cache cache;
+
+ FlushAllDelayed(Cache cache) {
+ this.cache = cache;
+ }
+
+ @Override
+ public void run() {
+ cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_STORE).clear();
+ }
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/GetCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/GetCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/GetCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.Channel;
+import org.infinispan.server.core.ChannelBuffer;
+import org.infinispan.server.core.ChannelBuffers;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
+import static org.infinispan.server.memcached.Reply.VALUE;
+import static org.infinispan.server.memcached.Reply.END;
+
+/**
+ * GetCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class GetCommand extends RetrievalCommand {
+
+ GetCommand(Cache<String, Value> cache, CommandType type, RetrievalParameters params) {
+ super(cache, type, params);
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitGet(ctx, this);
+ }
+
+ @Override
+ public Object perform(ChannelHandlerContext ctx) throws Throwable {
+ Channel ch = ctx.getChannel();
+ ChannelBuffer buffer;
+ ChannelBuffers buffers = ctx.getChannelBuffers();
+ for (String key : params.keys) {
+ Value value = cache.get(key);
+ if (value != null) {
+ StringBuilder sb = constructValue(key, value);
+ buffer = buffers.wrappedBuffer(buffers.wrappedBuffer(sb.toString().getBytes()), buffers.wrappedBuffer(CRLF),
+ buffers.wrappedBuffer(value.getData()), buffers.wrappedBuffer(CRLF));
+ ch.write(buffer);
+ }
+ }
+
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(END.bytes()), buffers.wrappedBuffer(CRLF)));
+ return END;
+ }
+
+ protected StringBuilder constructValue(String key, Value value) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(VALUE).append(" ")
+ .append(key).append(" ")
+ .append(value.getFlags()).append(" ")
+ .append(value.getData().length).append(" ");
+ return sb;
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/GetsCommand.java (from rev 1329, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/GetsCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/GetsCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/GetsCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import org.infinispan.Cache;
+
+/**
+ * GetsCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class GetsCommand extends GetCommand {
+
+ GetsCommand(Cache cache, CommandType type, RetrievalParameters params) {
+ super(cache, type, params);
+ }
+
+ @Override
+ protected StringBuilder constructValue(String key, Value value) {
+ return super.constructValue(key, value).append(value.getCas()).append(" ");
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/IncrementCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/IncrementCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/IncrementCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/IncrementCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.math.BigInteger;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
+/**
+ * IncrementCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class IncrementCommand extends NumericCommand {
+ private static final Log log = LogFactory.getLog(IncrementCommand.class);
+
+ public IncrementCommand(Cache cache, CommandType type, String key, BigInteger value) {
+ super(cache, type, key, value);
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitIncrement(ctx, this);
+ }
+
+ @Override
+ protected BigInteger operate(BigInteger oldValue, BigInteger newValue) {
+ if (log.isTraceEnabled()) log.trace("Increment {0} with {1}", oldValue, newValue);
+ return oldValue.add(newValue);
+ }
+
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/MemcachedStats.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStats.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/MemcachedStats.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/MemcachedStats.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+/**
+ * MemcachedStats.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public interface MemcachedStats {
+
+ long getIncrMisses();
+
+ long getIncrHits();
+
+ long getDecrMisses();
+
+ long getDecrHits();
+
+ long getCasMisses();
+
+ long getCasHits();
+
+ long getCasBadval();
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/MemcachedStatsImpl.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/MemcachedStatsImpl.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/MemcachedStatsImpl.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/MemcachedStatsImpl.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.util.List;
+
+import org.infinispan.stats.Stats;
+import org.infinispan.server.core.CommandInterceptor;
+import org.infinispan.server.core.InterceptorChain;
+import org.infinispan.server.memcached.interceptors.StatsInterceptor;
+
+/**
+ * MemcachedStats.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class MemcachedStatsImpl implements MemcachedStats, Stats {
+ final Stats cacheStats;
+ final long incrMisses;
+ final long incrHits;
+ final long decrMisses;
+ final long decrHits;
+ final long casMisses;
+ final long casHits;
+ final long casBadval;
+
+ MemcachedStatsImpl(Stats cacheStats, InterceptorChain chain) {
+ this.cacheStats = cacheStats;
+ List<CommandInterceptor> interceptors = chain.getInterceptorsWhichExtend(StatsInterceptor.class);
+ if (!interceptors.isEmpty()) {
+ StatsInterceptor statsInt = (StatsInterceptor) interceptors.get(0);
+ incrMisses = statsInt.getIncrMisses();
+ incrHits = statsInt.getIncrHits();
+ decrMisses = statsInt.getDecrMisses();
+ decrHits = statsInt.getDecrHits();
+ casMisses = statsInt.getCasMisses();
+ casHits = statsInt.getCasHits();
+ casBadval = statsInt.getCasBadval();
+ } else {
+ incrMisses = -1;
+ incrHits = -1;
+ decrMisses = -1;
+ decrHits = -1;
+ casMisses = -1;
+ casHits = -1;
+ casBadval = -1;
+ }
+ }
+
+ public long getCasBadval() {
+ return casBadval;
+ }
+
+ public long getCasHits() {
+ return casHits;
+ }
+
+ public long getCasMisses() {
+ return casMisses;
+ }
+
+ public long getDecrHits() {
+ return decrHits;
+ }
+
+ public long getDecrMisses() {
+ return decrMisses;
+ }
+
+ public long getIncrHits() {
+ return incrHits;
+ }
+
+ public long getIncrMisses() {
+ return incrMisses;
+ }
+
+ public int getCurrentNumberOfEntries() {
+ return cacheStats.getCurrentNumberOfEntries();
+ }
+
+ public long getEvictions() {
+ return cacheStats.getEvictions();
+ }
+
+ public long getHits() {
+ return cacheStats.getHits();
+ }
+
+ public long getMisses() {
+ return cacheStats.getMisses();
+ }
+
+ public long getRemoveHits() {
+ return cacheStats.getRemoveHits();
+ }
+
+ public long getRemoveMisses() {
+ return cacheStats.getRemoveMisses();
+ }
+
+ public long getRetrievals() {
+ return cacheStats.getRetrievals();
+ }
+
+ public long getStores() {
+ return cacheStats.getStores();
+ }
+
+ public long getTimeSinceStart() {
+ return cacheStats.getTimeSinceStart();
+ }
+
+ public long getTotalNumberOfEntries() {
+ return cacheStats.getTotalNumberOfEntries();
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/NumericCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/NumericCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/NumericCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/NumericCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
+
+import java.io.IOException;
+import java.io.StreamCorruptedException;
+import java.math.BigInteger;
+
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.infinispan.server.core.ChannelBuffers;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.core.Channel;
+import org.infinispan.server.memcached.Reply;
+
+/**
+ * NumericCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public abstract class NumericCommand implements TextCommand {
+ private static final Log log = LogFactory.getLog(NumericCommand.class);
+ final Cache cache;
+ private final CommandType type;
+ final String key;
+ final BigInteger value;
+
+ public NumericCommand(Cache cache, CommandType type, String key, BigInteger value) {
+ this.cache = cache;
+ this.type = type;
+ this.key = key;
+ this.value = value;
+ }
+
+ public CommandType getType() {
+ return type;
+ }
+
+ @Override
+ public Object perform(ChannelHandlerContext ctx) throws Throwable {
+ Channel ch = ctx.getChannel();
+ ChannelBuffers buffers = ctx.getChannelBuffers();
+ Value old = (Value) cache.get(key);
+ if (old != null) {
+ BigInteger oldBigInt = old.getData().length == 0 ? BigInteger.valueOf(0) : new BigInteger(old.getData());
+ BigInteger newBigInt = operate(oldBigInt, value);
+ byte[] newData = newBigInt.toByteArray();
+ Value curr = new Value(old.getFlags(), newData, old.getCas() + 1);
+ boolean replaced = cache.replace(key, old, curr);
+ if (replaced) {
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(newBigInt.toString().getBytes()), buffers.wrappedBuffer(CRLF)));
+ } else {
+ throw new CacheException("Value modified since we retrieved from the cache, old value was " + oldBigInt);
+ }
+ return curr;
+ } else {
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(Reply.NOT_FOUND.bytes()), buffers.wrappedBuffer(CRLF)));
+ return Reply.NOT_FOUND;
+ }
+ }
+
+ protected abstract BigInteger operate(BigInteger oldValue, BigInteger newValue);
+
+ public static TextCommand newNumericCommand(Cache cache, CommandType type, String key, BigInteger value) throws IOException {
+ switch(type) {
+ case INCR: return new IncrementCommand(cache, type, key, value);
+ case DECR: return new DecrementCommand(cache, type, key, value);
+ default: throw new StreamCorruptedException("Unable to build storage command for type: " + type);
+ }
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/PrependCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/PrependCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/PrependCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/PrependCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.TextProtocolUtil;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * PrependCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class PrependCommand extends AppendCommand {
+
+ PrependCommand(Cache cache, CommandType type, StorageParameters params, byte[] data) {
+ super(cache, type, params, data);
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitPrepend(ctx, this);
+ }
+
+ @Override
+ protected byte[] concat(byte[] current, byte[] prepend) {
+ return TextProtocolUtil.concat(prepend, current);
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/QuitCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/QuitCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/QuitCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/QuitCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import org.infinispan.server.core.Channel;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * QuitCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public enum QuitCommand implements TextCommand {
+ INSTANCE;
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitQuit(ctx, this);
+ }
+
+ @Override
+ public CommandType getType() {
+ return CommandType.QUIT;
+ }
+
+ @Override
+ public Object perform(ChannelHandlerContext ctx) throws Throwable {
+ Channel ch = ctx.getChannel();
+ ch.disconnect();
+ return null;
+ }
+
+ public static QuitCommand newQuitCommand() {
+ return INSTANCE;
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/ReplaceCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/ReplaceCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/ReplaceCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/ReplaceCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.util.concurrent.TimeUnit;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.Reply;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * ReplaceCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class ReplaceCommand extends SetCommand {
+
+ ReplaceCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
+ super(cache, type, params, data);
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitReplace(ctx, this);
+ }
+
+ @Override
+ protected Reply put(String key, int flags, byte[] data, long expiry) {
+ Value old = cache.get(key);
+ if (old != null) {
+ Value value = new Value(flags, data, old.getCas() + 1);
+ boolean replaced = cache.replace(params.key, old, value, expiry, TimeUnit.MILLISECONDS);
+ return reply(replaced);
+ }
+ return reply(old);
+ }
+
+ private Reply reply(Value prev) {
+ if (prev == null)
+ return Reply.NOT_STORED;
+ else
+ return Reply.STORED;
+ }
+
+ private Reply reply(boolean replaced) {
+ if (!replaced)
+ return Reply.NOT_STORED;
+ else
+ return Reply.STORED;
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/RetrievalCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/RetrievalCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/RetrievalCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import org.infinispan.Cache;
+
+/**
+ * RetrievalCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public abstract class RetrievalCommand implements TextCommand {
+ final Cache<String, Value> cache;
+ private final CommandType type;
+ final RetrievalParameters params;
+
+ RetrievalCommand(Cache<String, Value> cache, CommandType type, RetrievalParameters params) {
+ this.cache = cache;
+ this.type = type;
+ this.params = params;
+ }
+
+ @Override
+ public CommandType getType() {
+ return type;
+ }
+
+ public static TextCommand newRetrievalCommand(Cache<String, Value> cache, CommandType type, RetrievalParameters params) {
+ switch(type) {
+ case GET: return new GetCommand(cache, type, params);
+ case GETS: return new GetsCommand(cache, type, params);
+ default: throw new IllegalStateException("Unable to build storage command for type: " + type);
+ }
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/RetrievalParameters.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/RetrievalParameters.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/RetrievalParameters.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/RetrievalParameters.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.util.List;
+
+/**
+ * RetrievalParameters.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class RetrievalParameters {
+ final List<String> keys;
+
+ RetrievalParameters(List<String> keys) {
+ this.keys = keys;
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/SetCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/SetCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/SetCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/SetCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+import org.infinispan.server.core.Channel;
+import org.infinispan.server.core.ChannelBuffers;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.Reply;
+import org.infinispan.server.memcached.TextProtocolUtil;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
+import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
+
+/**
+ * SetCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class SetCommand extends StorageCommand {
+ private static final Log log = LogFactory.getLog(SetCommand.class);
+
+ SetCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
+ super(cache, type, params, data);
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitSet(ctx, this);
+ }
+
+ @Override
+ public Object perform(ChannelHandlerContext ctx) throws Exception {
+ Channel ch = ctx.getChannel();
+ Reply reply;
+ try {
+ if (params.expiry == 0) {
+ reply = put(params.key, params.flags, data);
+ } else {
+ if (params.expiry > TextProtocolUtil.SECONDS_IN_A_MONTH) {
+ // If expiry bigger number of seconds in 30 days, then it's considered unix time
+ long future = TimeUnit.SECONDS.toMillis(params.expiry);
+ long expiry = future - System.currentTimeMillis();
+ if (expiry > 0) {
+ reply = put(params.key, params.flags, data, expiry);
+ } else {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Given expiry is bigger than 30 days, hence is treated as Unix time, ")
+ .append("but this time is in the past: ").append(future)
+ .append(", date: ").append(new Date(future));
+ throw new CacheException(sb.toString());
+ }
+ } else {
+ // Convert seconds to milliseconds to simplify code
+ long expiry = TimeUnit.SECONDS.toMillis(params.expiry);
+ reply = put(params.key, params.flags, data, expiry);
+ }
+ }
+
+ } catch (Exception e) {
+ log.error("Unexpected exception performing command", e);
+ reply = Reply.NOT_STORED;
+ }
+ ChannelBuffers buffers = ctx.getChannelBuffers();
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(reply.bytes()), buffers.wrappedBuffer(CRLF)));
+ return reply;
+ }
+
+ protected Reply put(String key, int flags, byte[] data) {
+ return put(key, flags, data, -1);
+ }
+
+ protected Reply put(String key, int flags, byte[] data, long expiry) {
+ Value prev = cache.get(key);
+ Value value;
+ if (prev != null) {
+ value = new Value(flags, data, prev.getCas() + 1);
+ boolean replaced = cache.replace(key, prev, value, expiry, TimeUnit.MILLISECONDS);
+ return reply(replaced);
+ } else {
+ value = new Value(flags, data, System.currentTimeMillis());
+ prev = cache.putIfAbsent(key, value, expiry, TimeUnit.MILLISECONDS);
+ return reply(prev);
+ }
+ }
+
+ private Reply reply(boolean replaced) {
+ if (!replaced)
+ return Reply.NOT_STORED;
+ else
+ return Reply.STORED;
+ }
+
+ private Reply reply(Value prev) {
+ if (prev == null)
+ return Reply.STORED;
+ else
+ return Reply.NOT_STORED;
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StatsCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StatsCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StatsCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import static org.infinispan.server.memcached.Reply.END;
+import static org.infinispan.server.memcached.Reply.STAT;
+import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
+
+import java.util.concurrent.TimeUnit;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.Channel;
+import org.infinispan.server.core.ChannelBuffers;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.core.InterceptorChain;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * StatsCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class StatsCommand implements TextCommand {
+ final Cache cache;
+ private final CommandType type;
+ final InterceptorChain chain;
+
+ StatsCommand(Cache cache, CommandType type, InterceptorChain chain) {
+ this.cache = cache;
+ this.type = type;
+ this.chain = chain;
+ }
+
+ @Override
+ public CommandType getType() {
+ return CommandType.STATS;
+ }
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitStats(ctx, this);
+ }
+
+ @Override
+ public Object perform(ChannelHandlerContext ctx) throws Throwable {
+ MemcachedStatsImpl stats = new MemcachedStatsImpl(cache.getAdvancedCache().getStats(), chain);
+
+ StringBuilder sb = new StringBuilder();
+ writeStat("pid", 0, sb, ctx); // Unsupported
+ writeStat("uptime", stats.getTimeSinceStart(), sb, ctx);
+ writeStat("time", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()), sb, ctx);
+ writeStat("version", cache.getVersion(), sb, ctx);
+ writeStat("pointer_size", 0, sb, ctx); // Unsupported
+ writeStat("rusage_user", 0, sb, ctx); // Unsupported
+ writeStat("rusage_system", 0, sb, ctx); // Unsupported
+ writeStat("curr_items", stats.getCurrentNumberOfEntries(), sb, ctx);
+ writeStat("total_items", stats.getTotalNumberOfEntries(), sb, ctx);
+ writeStat("bytes", 0, sb, ctx); // Unsupported
+ writeStat("curr_connections", 0, sb, ctx); // TODO: Through netty?
+ writeStat("total_connections", 0, sb, ctx); // TODO: Through netty?
+ writeStat("connection_structures", 0, sb, ctx); // Unsupported
+ writeStat("cmd_get", stats.getRetrievals(), sb, ctx);
+ writeStat("cmd_set", stats.getStores(), sb, ctx);
+ writeStat("get_hits", stats.getHits(), sb, ctx);
+ writeStat("get_misses", stats.getMisses(), sb, ctx);
+ writeStat("delete_misses", stats.getRemoveMisses(), sb, ctx);
+ writeStat("delete_hits", stats.getRemoveHits(), sb, ctx);
+ writeStat("incr_misses", stats.getIncrMisses(), sb, ctx);
+ writeStat("incr_hits", stats.getIncrHits(), sb, ctx);
+ writeStat("decr_misses", stats.getDecrMisses(), sb, ctx);
+ writeStat("decr_hits", stats.getDecrHits(), sb, ctx);
+ writeStat("cas_misses", stats.getCasMisses(), sb, ctx);
+ writeStat("cas_hits", stats.getCasHits(), sb, ctx);
+ writeStat("cas_badval", stats.getCasBadval(), sb, ctx);
+ writeStat("auth_cmds", 0, sb, ctx); // Unsupported
+ writeStat("auth_errors", 0, sb, ctx); // Unsupported
+ //TODO: Evictions are measure by evict calls, but not by nodes are that
+ // are expired after the entry's lifespan has expired.
+ writeStat("evictions", stats.getEvictions(), sb, ctx);
+ writeStat("bytes_read", 0, sb, ctx); // TODO: Through netty?
+ writeStat("bytes_written", 0, sb, ctx); // TODO: Through netty?
+ writeStat("limit_maxbytes", 0, sb, ctx); // Unsupported
+ writeStat("threads", 0, sb, ctx); // TODO: Through netty?
+ writeStat("conn_yields", 0, sb, ctx); // Unsupported
+
+ ChannelBuffers buffers = ctx.getChannelBuffers();
+ Channel ch = ctx.getChannel();
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(END.bytes()), buffers.wrappedBuffer(CRLF)));
+
+ return END;
+ }
+
+ private void writeStat(String stat, Object value, StringBuilder sb, ChannelHandlerContext ctx) {
+ ChannelBuffers buffers = ctx.getChannelBuffers();
+ Channel ch = ctx.getChannel();
+ sb.append(STAT).append(' ').append(stat).append(' ').append(value);
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(sb.toString().getBytes()), buffers.wrappedBuffer(CRLF)));
+ sb.setLength(0);
+ }
+
+ public static TextCommand newStatsCommand(Cache cache, CommandType type, InterceptorChain chain) {
+ return new StatsCommand(cache, type, chain);
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StorageCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StorageCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StorageCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.io.IOException;
+import java.io.StreamCorruptedException;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.Command;
+
+/**
+ * StorageCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public abstract class StorageCommand implements TextCommand {
+ private final CommandType type;
+ final Cache<String, Value> cache;
+ final StorageParameters params;
+ final byte[] data;
+
+ StorageCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) {
+ this.type = type;
+ this.params = params;
+ this.cache = cache;
+ this.data = data;
+ }
+
+ public CommandType getType() {
+ return type;
+ }
+
+ public Command setData(byte[] data) throws IOException {
+ return newStorageCommand(cache, type, params, data);
+ }
+
+ public StorageParameters getParams() {
+ return params;
+ }
+
+ public static TextCommand newStorageCommand(Cache<String, Value> cache, CommandType type, StorageParameters params, byte[] data) throws IOException {
+ switch(type) {
+ case SET: return new SetCommand(cache, type, params, data);
+ case ADD: return new AddCommand(cache, type, params, data);
+ case REPLACE: return new ReplaceCommand(cache, type, params, data);
+ case APPEND: return new AppendCommand(cache, type, params, data);
+ case PREPEND: return new PrependCommand(cache, type, params, data);
+ default: throw new StreamCorruptedException("Unable to build storage command for type: " + type);
+ }
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StorageParameters.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StorageParameters.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StorageParameters.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/StorageParameters.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+/**
+ * StorageParameters.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class StorageParameters {
+ final String key;
+ final int flags;
+ final long expiry;
+ final int bytes;
+ boolean noreply;
+
+ StorageParameters(String key, int flags, long expiry, int bytes) {
+ this.key = key;
+ this.flags = flags;
+ this.expiry = expiry;
+ this.bytes = bytes;
+ }
+
+ public int getBytes() {
+ return bytes;
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/TextCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/TextCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/TextCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.core.Command;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+/**
+ * TextCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public interface TextCommand extends Command {
+ Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable;
+ CommandType getType();
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/TextCommandHandler.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandHandler.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/TextCommandHandler.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/TextCommandHandler.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.core.CommandHandler;
+import org.infinispan.server.core.MessageEvent;
+import org.infinispan.server.core.InterceptorChain;
+
+/**
+ * TextProtocolServerHandler.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+class TextCommandHandler implements CommandHandler {
+ final Cache cache;
+ final InterceptorChain chain;
+
+ public TextCommandHandler(Cache cache, InterceptorChain chain) {
+ this.cache = cache;
+ this.chain = chain;
+ }
+
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Throwable {
+ chain.invoke(ctx, (TextCommand) e.getMessage());
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/Value.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Value.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/Value.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/Value.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+
+/**
+ * Value.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+class Value implements Externalizable {
+ private int flags;
+ private byte[] data;
+ private long cas;
+
+ Value(int flags, byte[] data, long cas) {
+ this.flags = flags;
+ this.data = data;
+ this.cas = cas;
+ }
+
+ public int getFlags() {
+ return flags;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public long getCas() {
+ return cas;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (!(obj instanceof Value))
+ return false;
+ Value other = (Value) obj;
+ return Arrays.equals(data, other.data)
+ && flags == other.flags
+ && cas == other.cas;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 31 * result + flags;
+ result = 31 * result + data.hashCode();
+ result = 31 * result + (int)(cas ^ (cas >>> 32));
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "{" +
+ "data=" + Arrays.toString(data) +
+ ", flags=" + flags +
+ ", cas=" + cas +
+ "}";
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ flags = in.read();
+ data = new byte[in.read()];
+ in.read(data);
+ cas = in.readLong();
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.write(flags);
+ out.write(data.length);
+ out.write(data);
+ out.writeLong(cas);
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/VersionCommand.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/VersionCommand.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/VersionCommand.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/commands/VersionCommand.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.commands;
+
+import static org.infinispan.server.memcached.Reply.VERSION;
+
+import static org.infinispan.server.memcached.TextProtocolUtil.CRLF;
+
+import org.infinispan.Version;
+import org.infinispan.server.core.Channel;
+import org.infinispan.server.core.ChannelBuffers;
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.interceptors.TextProtocolVisitor;
+
+
+/**
+ * VersionCommand.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public enum VersionCommand implements TextCommand {
+ INSTANCE;
+
+ @Override
+ public Object acceptVisitor(ChannelHandlerContext ctx, TextProtocolVisitor next) throws Throwable {
+ return next.visitVersion(ctx, this);
+ }
+
+ @Override
+ public CommandType getType() {
+ return CommandType.VERSION;
+ }
+
+ @Override
+ public Object perform(ChannelHandlerContext ctx) throws Exception {
+ Channel ch = ctx.getChannel();
+ String version = ' ' + Version.version;
+ ChannelBuffers buffers = ctx.getChannelBuffers();
+ ch.write(buffers.wrappedBuffer(buffers.wrappedBuffer(VERSION.bytes()), buffers.wrappedBuffer(version.getBytes()), buffers.wrappedBuffer(CRLF)));
+ return VERSION;
+ }
+
+ public static VersionCommand newVersionCommand() {
+ return INSTANCE;
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/AbstractVisitor.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/AbstractVisitor.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/AbstractVisitor.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/AbstractVisitor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.interceptors;
+
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.commands.AddCommand;
+import org.infinispan.server.memcached.commands.AppendCommand;
+import org.infinispan.server.memcached.commands.CasCommand;
+import org.infinispan.server.memcached.commands.DecrementCommand;
+import org.infinispan.server.memcached.commands.DeleteCommand;
+import org.infinispan.server.memcached.commands.FlushAllCommand;
+import org.infinispan.server.memcached.commands.GetCommand;
+import org.infinispan.server.memcached.commands.GetsCommand;
+import org.infinispan.server.memcached.commands.IncrementCommand;
+import org.infinispan.server.memcached.commands.PrependCommand;
+import org.infinispan.server.memcached.commands.QuitCommand;
+import org.infinispan.server.memcached.commands.ReplaceCommand;
+import org.infinispan.server.memcached.commands.SetCommand;
+import org.infinispan.server.memcached.commands.StatsCommand;
+import org.infinispan.server.memcached.commands.TextCommand;
+import org.infinispan.server.memcached.commands.VersionCommand;
+
+/**
+ * CommandInterceptor.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public abstract class AbstractVisitor implements TextProtocolVisitor {
+
+ @Override
+ public Object visitAdd(ChannelHandlerContext ctx, AddCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitAppend(ChannelHandlerContext ctx, AppendCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitCas(ChannelHandlerContext ctx, CasCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitDecrement(ChannelHandlerContext ctx, DecrementCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitDelete(ChannelHandlerContext ctx, DeleteCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitGet(ChannelHandlerContext ctx, GetCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitGets(ChannelHandlerContext ctx, GetsCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitIncrement(ChannelHandlerContext ctx, IncrementCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitPrepend(ChannelHandlerContext ctx, PrependCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitReplace(ChannelHandlerContext ctx, ReplaceCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitSet(ChannelHandlerContext ctx, SetCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitStats(ChannelHandlerContext ctx, StatsCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitFlushAll(ChannelHandlerContext ctx, FlushAllCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitVersion(ChannelHandlerContext ctx, VersionCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public Object visitQuit(ChannelHandlerContext ctx, QuitCommand command) throws Throwable {
+ return handleDefault(ctx, command);
+ }
+
+ protected Object handleDefault(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
+ return null;
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/CallInterceptor.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/CallInterceptor.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/CallInterceptor.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/CallInterceptor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.interceptors;
+
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.commands.TextCommand;
+
+/**
+ * CallInterceptor.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class CallInterceptor extends TextCommandInterceptorImpl {
+
+ public CallInterceptor(TextCommandInterceptor next) {
+ super(next);
+ }
+
+ @Override
+ protected Object handleDefault(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
+ return command.perform(ctx);
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/StatsInterceptor.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/StatsInterceptor.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/StatsInterceptor.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/StatsInterceptor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.interceptors;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.Reply;
+import org.infinispan.server.memcached.commands.CasCommand;
+import org.infinispan.server.memcached.commands.DecrementCommand;
+import org.infinispan.server.memcached.commands.IncrementCommand;
+import org.infinispan.server.memcached.commands.MemcachedStats;
+
+/**
+ * StatsInterceptor.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class StatsInterceptor extends TextCommandInterceptorImpl implements MemcachedStats {
+ private final AtomicLong incrMisses = new AtomicLong(0);
+ private final AtomicLong incrHits = new AtomicLong(0);
+ private final AtomicLong decrMisses = new AtomicLong(0);
+ private final AtomicLong decrHits = new AtomicLong(0);
+ private final AtomicLong casMisses = new AtomicLong(0);
+ private final AtomicLong casHits = new AtomicLong(0);
+ private final AtomicLong casBadval = new AtomicLong(0);
+
+ public StatsInterceptor(TextCommandInterceptor next) {
+ super(next);
+ }
+
+ @Override
+ public Object visitIncrement(ChannelHandlerContext ctx, IncrementCommand command) throws Throwable {
+ Object ret = invokeNextInterceptor(ctx, command);
+ if (ret != Reply.NOT_FOUND)
+ incrHits.incrementAndGet();
+ else
+ incrMisses.incrementAndGet();
+ return ret;
+ }
+
+ @Override
+ public Object visitDecrement(ChannelHandlerContext ctx, DecrementCommand command) throws Throwable {
+ Object ret = invokeNextInterceptor(ctx, command);
+ if (ret != Reply.NOT_FOUND)
+ decrHits.incrementAndGet();
+ else
+ decrMisses.incrementAndGet();
+ return ret;
+ }
+
+ @Override
+ public Object visitCas(ChannelHandlerContext ctx, CasCommand command) throws Throwable {
+ Reply ret = (Reply) invokeNextInterceptor(ctx, command);
+ switch (ret) {
+ case STORED:
+ casHits.incrementAndGet();
+ break;
+ case NOT_FOUND:
+ casMisses.incrementAndGet();
+ break;
+ case EXISTS:
+ casBadval.incrementAndGet();
+ break;
+ }
+ return ret;
+ }
+
+ @Override
+ public long getIncrHits() {
+ return incrHits.get();
+ }
+
+ @Override
+ public long getIncrMisses() {
+ return incrMisses.get();
+ }
+
+ @Override
+ public long getDecrHits() {
+ return decrHits.get();
+ }
+
+ @Override
+ public long getDecrMisses() {
+ return decrMisses.get();
+ }
+
+ @Override
+ public long getCasBadval() {
+ return casBadval.get();
+ }
+
+ @Override
+ public long getCasHits() {
+ return casHits.get();
+ }
+
+ @Override
+ public long getCasMisses() {
+ return casMisses.get();
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextCommandInterceptor.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptor.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextCommandInterceptor.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextCommandInterceptor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.interceptors;
+
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.core.CommandInterceptor;
+import org.infinispan.server.memcached.commands.TextCommand;
+
+/**
+ * TextCommandInterceptor.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public interface TextCommandInterceptor extends CommandInterceptor, TextProtocolVisitor {
+ Object invokeNextInterceptor(ChannelHandlerContext ctx, TextCommand command) throws Throwable;
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextCommandInterceptorImpl.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextCommandInterceptorImpl.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextCommandInterceptorImpl.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextCommandInterceptorImpl.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.interceptors;
+
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.core.CommandInterceptor;
+import org.infinispan.server.memcached.commands.TextCommand;
+
+/**
+ * TextCommandInterceptorImpl.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class TextCommandInterceptorImpl extends AbstractVisitor implements TextCommandInterceptor {
+ private final TextCommandInterceptor next;
+
+ TextCommandInterceptorImpl(TextCommandInterceptor next) {
+ this.next = next;
+ }
+
+ @Override
+ public Object invokeNextInterceptor(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
+ return command.acceptVisitor(ctx, next);
+ }
+
+ @Override
+ public CommandInterceptor getNext() {
+ return next;
+ }
+
+ @Override
+ protected Object handleDefault(ChannelHandlerContext ctx, TextCommand command) throws Throwable {
+ return invokeNextInterceptor(ctx, command);
+ }
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolInterceptorChain.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChain.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolInterceptorChain.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolInterceptorChain.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.interceptors;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.core.Command;
+import org.infinispan.server.core.CommandInterceptor;
+import org.infinispan.server.core.InterceptorChain;
+import org.infinispan.server.memcached.commands.TextCommand;
+
+/**
+ * TextProtocolInterceptorChain.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class TextProtocolInterceptorChain implements InterceptorChain {
+
+ private final TextCommandInterceptor firstInChain;
+
+ public TextProtocolInterceptorChain(TextCommandInterceptor firstInChain) {
+ this.firstInChain = firstInChain;
+ }
+
+ @Override
+ public Object invoke(ChannelHandlerContext ctx, Command command) throws Throwable {
+ return ((TextCommand) command).acceptVisitor(ctx, firstInChain);
+ }
+
+ public List<CommandInterceptor> getInterceptorsWhichExtend(Class<? extends CommandInterceptor> interceptorClass) {
+ List<CommandInterceptor> result = new ArrayList<CommandInterceptor>();
+ for (CommandInterceptor interceptor : asList()) {
+ boolean isSubclass = interceptorClass.isAssignableFrom(interceptor.getClass());
+ if (isSubclass) {
+ result.add(interceptor);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns an unmofiable list with all the interceptors in sequence. If first in chain is null an empty list is
+ * returned.
+ */
+ private List<CommandInterceptor> asList() {
+ if (firstInChain == null) return Collections.emptyList();
+
+ List<CommandInterceptor> retval = new LinkedList<CommandInterceptor>();
+ CommandInterceptor tmp = firstInChain;
+ do {
+ retval.add(tmp);
+ tmp = tmp.getNext();
+ }
+ while (tmp != null);
+ return Collections.unmodifiableList(retval);
+ }
+
+
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolInterceptorChainFactory.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolInterceptorChainFactory.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolInterceptorChainFactory.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolInterceptorChainFactory.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.interceptors;
+
+import org.infinispan.Cache;
+import org.infinispan.server.core.InterceptorChainFactory;
+import org.infinispan.server.core.InterceptorChain;
+
+/**
+ * InterceptorChainFactory.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public enum TextProtocolInterceptorChainFactory implements InterceptorChainFactory {
+ STATS_ENABLED(true), NOT_STATS_ENABLED(false);
+
+ private final boolean statsEnabled;
+
+ private TextProtocolInterceptorChainFactory(boolean statsEnabled) {
+ this.statsEnabled = statsEnabled;
+ }
+
+ public InterceptorChain buildInterceptorChain() {
+ TextCommandInterceptor first;
+ if (statsEnabled) {
+ first = new StatsInterceptor(new CallInterceptor(null));
+ } else {
+ first = new CallInterceptor(null);
+ }
+
+ return new TextProtocolInterceptorChain(first);
+ }
+
+ public static TextProtocolInterceptorChainFactory getInstance(Cache cache) {
+ if (cache.getConfiguration().isExposeJmxStatistics())
+ return STATS_ENABLED;
+ else
+ return NOT_STATS_ENABLED;
+ }
+}
Copied: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolVisitor.java (from rev 1337, trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextProtocolVisitor.java)
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolVisitor.java (rev 0)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/interceptors/TextProtocolVisitor.java 2009-12-30 19:52:30 UTC (rev 1338)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.memcached.interceptors;
+
+import org.infinispan.server.core.ChannelHandlerContext;
+import org.infinispan.server.memcached.commands.AddCommand;
+import org.infinispan.server.memcached.commands.AppendCommand;
+import org.infinispan.server.memcached.commands.CasCommand;
+import org.infinispan.server.memcached.commands.DecrementCommand;
+import org.infinispan.server.memcached.commands.DeleteCommand;
+import org.infinispan.server.memcached.commands.FlushAllCommand;
+import org.infinispan.server.memcached.commands.GetCommand;
+import org.infinispan.server.memcached.commands.GetsCommand;
+import org.infinispan.server.memcached.commands.IncrementCommand;
+import org.infinispan.server.memcached.commands.PrependCommand;
+import org.infinispan.server.memcached.commands.QuitCommand;
+import org.infinispan.server.memcached.commands.ReplaceCommand;
+import org.infinispan.server.memcached.commands.SetCommand;
+import org.infinispan.server.memcached.commands.StatsCommand;
+import org.infinispan.server.memcached.commands.VersionCommand;
+
+/**
+ * CommandInterceptor.
+ *
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public interface TextProtocolVisitor {
+ Object visitSet(ChannelHandlerContext ctx, SetCommand command) throws Throwable;
+ Object visitAdd(ChannelHandlerContext ctx, AddCommand command) throws Throwable;
+ Object visitReplace(ChannelHandlerContext ctx, ReplaceCommand command) throws Throwable;
+ Object visitAppend(ChannelHandlerContext ctx, AppendCommand command) throws Throwable;
+ Object visitPrepend(ChannelHandlerContext ctx, PrependCommand command) throws Throwable;
+ Object visitCas(ChannelHandlerContext ctx, CasCommand command) throws Throwable;
+ Object visitGet(ChannelHandlerContext ctx, GetCommand command) throws Throwable;
+ Object visitGets(ChannelHandlerContext ctx, GetsCommand command) throws Throwable;
+ Object visitDelete(ChannelHandlerContext ctx, DeleteCommand command) throws Throwable;
+ Object visitIncrement(ChannelHandlerContext ctx, IncrementCommand command) throws Throwable;
+ Object visitDecrement(ChannelHandlerContext ctx, DecrementCommand command) throws Throwable;
+ Object visitStats(ChannelHandlerContext ctx, StatsCommand command) throws Throwable;
+ Object visitFlushAll(ChannelHandlerContext ctx, FlushAllCommand command) throws Throwable;
+ Object visitVersion(ChannelHandlerContext ctx, VersionCommand command) throws Throwable;
+ Object visitQuit(ChannelHandlerContext ctx, QuitCommand command) throws Throwable;
+}
More information about the infinispan-commits
mailing list