Repository: ignite Updated Branches: refs/heads/ignite-2788 127f459fa -> a8dae9d00
http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisThruRestCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisThruRestCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisThruRestCommandHandler.java deleted file mode 100644 index 21f3de2..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisThruRestCommandHandler.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler; - -import java.nio.ByteBuffer; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisTypeException; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.future.GridFinishedFuture; -import org.apache.ignite.internal.util.typedef.CX1; - -/** - * Redis command handler done via REST. - */ -public abstract class GridRedisThruRestCommandHandler implements GridRedisCommandHandler { - /** REST protocol handler. */ - protected final GridRestProtocolHandler hnd; - - /** - * Constructor. - * - * @param ctx Context. - * @param hnd REST protocol handler. - */ - public GridRedisThruRestCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - this.hnd = hnd; - } - - /** {@inheritDoc} */ - @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(final GridRedisMessage msg) { - assert msg != null; - - try { - return hnd.handleAsync(asRestRequest(msg)) - .chain(new CX1<IgniteInternalFuture<GridRestResponse>, GridRedisMessage>() { - @Override - public GridRedisMessage applyx(IgniteInternalFuture<GridRestResponse> f) - throws IgniteCheckedException { - GridRestResponse restRes = f.get(); - - if (restRes.getSuccessStatus() == GridRestResponse.STATUS_SUCCESS) - msg.setResponse(makeResponse(restRes, msg.auxMKeys())); - else - msg.setResponse(GridRedisProtocolParser.toGenericError("Operation error!")); - - return msg; - } - }); - } - catch (IgniteCheckedException e) { - if (e instanceof GridRedisTypeException) - msg.setResponse(GridRedisProtocolParser.toTypeError(e.getMessage())); - else - msg.setResponse(GridRedisProtocolParser.toGenericError(e.getMessage())); - - return new GridFinishedFuture<>(msg); - } - } - - /** - * Converts {@link GridRedisMessage} to {@link GridRestRequest}. - * - * @param msg {@link GridRedisMessage} - * @return {@link GridRestRequest} - * @throws IgniteCheckedException If fails. - */ - public abstract GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException; - - /** - * Prepares a response according to the request. - * - * @param resp REST response. - * @param params Auxiliary parameters. - * @return - */ - public abstract ByteBuffer makeResponse(GridRestResponse resp, List<String> params); -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisGenericException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisGenericException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisGenericException.java deleted file mode 100644 index 6c7c688..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisGenericException.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception; - -import org.apache.ignite.IgniteCheckedException; - -/** - * Generic Redis protocol exception. - */ -public class GridRedisGenericException extends IgniteCheckedException { - /** */ - private static final long serialVersionUID = 0L; - - /** - * Creates a generic exception with given error message. - * - * @param msg Error message. - */ - public GridRedisGenericException(String msg) { - super(msg); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisTypeException.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisTypeException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisTypeException.java deleted file mode 100644 index 99cb577..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/exception/GridRedisTypeException.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception; - -import org.apache.ignite.IgniteCheckedException; - -/** - * Exception on operation on the wrong data type. - */ -public class GridRedisTypeException extends IgniteCheckedException { - /** */ - private static final long serialVersionUID = 0L; - - /** - * Creates a type exception with given error message. - * - * @param msg Error message. - */ - public GridRedisTypeException(String msg) { - super(msg); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisDelCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisDelCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisDelCommandHandler.java deleted file mode 100644 index 6644082..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisDelCommandHandler.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.key; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REMOVE_ALL; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DEL; - -/** - * Redis DEL command handler. - */ -public class GridRedisDelCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - DEL - ); - - /** {@inheritDoc} */ - public GridRedisDelCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - if (msg.messageSize() < 2) - throw new GridRedisGenericException("Wrong number of arguments"); - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - restReq.command(CACHE_REMOVE_ALL); - - List<String> keys = msg.auxMKeys(); - Map<Object, Object> mget = U.newHashMap(keys.size()); - Iterator<String> mgetIt = keys.iterator(); - - while (mgetIt.hasNext()) - mget.put(mgetIt.next(), null); - - restReq.values(mget); - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - // It has to respond with the number of removed entries... - return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0") - : GridRedisProtocolParser.toInteger(String.valueOf(params.size()))); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisExistsCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisExistsCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisExistsCommandHandler.java deleted file mode 100644 index 4882603..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/key/GridRedisExistsCommandHandler.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.key; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.EXISTS; - -/** - * Redis EXISTS command handler. - */ -public class GridRedisExistsCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - EXISTS - ); - - /** {@inheritDoc} */ - public GridRedisExistsCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - if (msg.messageSize() < 2) - throw new GridRedisGenericException("Wrong number of arguments"); - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - restReq.command(CACHE_GET_ALL); - - List<String> keys = msg.auxMKeys(); - Map<Object, Object> mget = U.newHashMap(keys.size()); - Iterator<String> mgetIt = keys.iterator(); - - while (mgetIt.hasNext()) - mget.put(mgetIt.next(), null); - - restReq.values(mget); - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0") - : GridRedisProtocolParser.toInteger(((Map<Object, Object>)restRes.getResponse()).size())); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/server/GridRedisDbSizeCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/server/GridRedisDbSizeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/server/GridRedisDbSizeCommandHandler.java deleted file mode 100644 index b4de44c..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/server/GridRedisDbSizeCommandHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.server; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_SIZE; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DBSIZE; - -/** - * Redis DBSIZE command handler. - */ -public class GridRedisDbSizeCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - DBSIZE - ); - - /** {@inheritDoc} */ - public GridRedisDbSizeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - restReq.command(CACHE_SIZE); - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0") - : GridRedisProtocolParser.toInteger(String.valueOf(restRes.getResponse()))); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java deleted file mode 100644 index 0c4a744..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_APPEND; -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET; -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.APPEND; - -/** - * Redis APPEND command handler. - */ -public class GridRedisAppendCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - APPEND - ); - - /** Position of the value. */ - private static final int VAL_POS = 2; - - /** {@inheritDoc} */ - public GridRedisAppendCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - if (msg.messageSize() < 3) - throw new GridRedisGenericException("Wrong syntax!"); - - GridRestCacheRequest appendReq = new GridRestCacheRequest(); - GridRestCacheRequest getReq = new GridRestCacheRequest(); - - String val = msg.aux(VAL_POS); - - appendReq.clientId(msg.clientId()); - appendReq.key(msg.key()); - appendReq.value(val); - appendReq.command(CACHE_APPEND); - - if ((boolean)hnd.handle(appendReq).getResponse() == false) { - // append on on-existing key in REST returns false. - GridRestCacheRequest setReq = new GridRestCacheRequest(); - - setReq.clientId(msg.clientId()); - setReq.key(msg.key()); - setReq.value(val); - setReq.command(CACHE_PUT); - - hnd.handle(setReq); - } - - getReq.clientId(msg.clientId()); - getReq.key(msg.key()); - getReq.command(CACHE_GET); - - return getReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - if (restRes.getResponse() == null) - return GridRedisProtocolParser.nil(); - else { - int resLen = ((String)restRes.getResponse()).length(); - return GridRedisProtocolParser.toInteger(String.valueOf(resLen)); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java deleted file mode 100644 index 52779b3..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GET; - -/** - * Redis GET command handler. - */ -public class GridRedisGetCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - GET - ); - - /** {@inheritDoc} */ - public GridRedisGetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - - restReq.command(CACHE_GET); - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - return (restRes.getResponse() == null ? GridRedisProtocolParser.nil() - : GridRedisProtocolParser.toBulkString(restRes.getResponse())); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java deleted file mode 100644 index 6406f23..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GETRANGE; - -/** - * Redis SETRANGE command handler. - */ -public class GridRedisGetRangeCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - GETRANGE - ); - - /** Start offset position in Redis message parameters. */ - private static final int START_OFFSET_POS = 1; - - /** End offset position in Redis message parameters. */ - private static final int END_OFFSET_POS = 2; - - /** {@inheritDoc} */ - public GridRedisGetRangeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - if (msg.messageSize() < 4) - throw new GridRedisGenericException("Wrong number of arguments"); - - GridRestCacheRequest getReq = new GridRestCacheRequest(); - - getReq.clientId(msg.clientId()); - getReq.key(msg.key()); - getReq.command(CACHE_GET); - - return getReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - if (restRes.getResponse() == null) - return GridRedisProtocolParser.toBulkString(""); - else { - String res = String.valueOf(restRes.getResponse()); - int startOffset; - int endOffset; - - try { - startOffset = boundedStartOffset(Integer.parseInt(params.get(START_OFFSET_POS)), res.length()); - endOffset = boundedEndOffset(Integer.parseInt(params.get(END_OFFSET_POS)), res.length()); - } - catch (NumberFormatException e) { - return GridRedisProtocolParser.toGenericError("Offset is not an integer!"); - } - - return GridRedisProtocolParser.toBulkString(res.substring(startOffset, endOffset)); - } - } - - /** - * @param idx Index. - * @param size Bounds. - * @return Offset within the bounds. - */ - private int boundedStartOffset(int idx, int size) { - if (idx >= 0) - return Math.min(idx, size); - else - return size + idx; - } - - /** - * @param idx Index. - * @param size Bounds. - * @return Offset within the bounds. - */ - private int boundedEndOffset(int idx, int size) { - if (idx >= 0) - return Math.min(idx + 1, size); - else - return size + idx + 1; - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java deleted file mode 100644 index 7df2ac2..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_AND_PUT; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GETSET; - -/** - * Redis GETSET command handler. - */ -public class GridRedisGetSetCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - GETSET - ); - - /** Value position in Redis message. */ - private static final int VAL_POS = 2; - - /** {@inheritDoc} */ - public GridRedisGetSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - if (msg.messageSize() < 3) - throw new GridRedisGenericException("Wrong syntax!"); - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - restReq.value(msg.aux(VAL_POS)); - - restReq.command(CACHE_GET_AND_PUT); - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - return (restRes.getResponse() == null ? GridRedisProtocolParser.nil() - : GridRedisProtocolParser.toBulkString(restRes.getResponse())); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java deleted file mode 100644 index c479832..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException; -import org.apache.ignite.internal.processors.rest.request.DataStructuresRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.ATOMIC_DECREMENT; -import static org.apache.ignite.internal.processors.rest.GridRestCommand.ATOMIC_INCREMENT; -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DECR; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DECRBY; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.INCR; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.INCRBY; - -/** - * Redis INCR/DECR command handler. - */ -public class GridRedisIncrDecrCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - INCR, - DECR, - INCRBY, - DECRBY - ); - - /** Delta position in the message. */ - private static final int DELTA_POS = 2; - - /** {@inheritDoc} */ - public GridRedisIncrDecrCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - DataStructuresRequest restReq = new DataStructuresRequest(); - - GridRestCacheRequest getReq = new GridRestCacheRequest(); - - getReq.clientId(msg.clientId()); - getReq.key(msg.key()); - getReq.command(CACHE_GET); - - GridRestResponse getResp = hnd.handle(getReq); - - if (getResp.getResponse() == null) { - restReq.initial(0L); - } - else { - if (getResp.getResponse() instanceof Long && (Long)getResp.getResponse() <= Long.MAX_VALUE) - restReq.initial((Long)getResp.getResponse()); - else - throw new GridRedisGenericException("An initial value must be numeric and in range!"); - } - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - restReq.delta(1L); - - if (msg.messageSize() > 2) { - try { - restReq.delta(Long.valueOf(msg.aux(DELTA_POS))); - } - catch (NumberFormatException e) { - throw new GridRedisGenericException("An increment value must be numeric and in range!"); - } - } - - switch (msg.command()) { - case INCR: - case INCRBY: - restReq.command(ATOMIC_INCREMENT); - break; - - case DECR: - case DECRBY: - restReq.command(ATOMIC_DECREMENT); - break; - } - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - if (restRes.getResponse() == null) - return GridRedisProtocolParser.toGenericError("Failed to increment!"); - - if (restRes.getResponse() instanceof Long && (Long)restRes.getResponse() <= Long.MAX_VALUE) - return GridRedisProtocolParser.toInteger(new BigDecimal((Long)restRes.getResponse()).toString()); - else - return GridRedisProtocolParser.toTypeError("Value is non-numeric or out of range!"); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java deleted file mode 100644 index 846b997..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.MGET; - -/** - * Redis MGET command handler. - */ -public class GridRedisMGetCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - MGET - ); - - /** {@inheritDoc} */ - public GridRedisMGetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - if (msg.messageSize() < 2) - throw new GridRedisGenericException("Wrong number of arguments"); - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - restReq.command(CACHE_GET_ALL); - - List<String> keys = msg.auxMKeys(); - Map<Object, Object> mget = U.newHashMap(keys.size()); - Iterator<String> mgetIt = keys.iterator(); - - while (mgetIt.hasNext()) - mget.put(mgetIt.next(), null); - - restReq.values(mget); - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - return (restRes.getResponse() == null ? GridRedisProtocolParser.nil() - : GridRedisProtocolParser.toArray((Map<Object, Object>)restRes.getResponse())); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java deleted file mode 100644 index cbb229a..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT_ALL; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.MSET; - -/** - * Redis MSET command handler. - */ -public class GridRedisMSetCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - MSET - ); - - /** {@inheritDoc} */ - public GridRedisMSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - - restReq.command(CACHE_PUT_ALL); - - List<String> els = msg.auxMKeys(); - Map<Object, Object> mset = U.newHashMap(els.size() / 2); - Iterator<String> msetIt = els.iterator(); - - while (msetIt.hasNext()) - mset.put(msetIt.next(), msetIt.hasNext() ? msetIt.next() : null); - - restReq.values(mset); - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - return GridRedisProtocolParser.OkString(); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java deleted file mode 100644 index 2c29766..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.SET; - -/** - * Redis SET command handler. - * <p> - * No key expiration is currently supported. - */ -public class GridRedisSetCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - SET - ); - - /** Value position in Redis message. */ - private static final int VAL_POS = 2; - - /** {@inheritDoc} */ - public GridRedisSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - - restReq.command(CACHE_PUT); - - if (msg.messageSize() < 3) - throw new IgniteCheckedException("Invalid request!"); - - restReq.value(msg.aux(VAL_POS)); - - if (msg.messageSize() >= 4) { - // handle options. - } - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - return (restRes.getResponse() == null ? GridRedisProtocolParser.nil() - : GridRedisProtocolParser.OkString()); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java deleted file mode 100644 index f559db3..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET; -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.SETRANGE; - -/** - * Redis SETRANGE command handler. - */ -public class GridRedisSetRangeCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - SETRANGE - ); - - /** Offset position in Redis message among parameters. */ - private static final int OFFSET_POS = 2; - - /** Value position in Redis message. */ - private static final int VAL_POS = 3; - - /** {@inheritDoc} */ - public GridRedisSetRangeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - if (msg.messageSize() < 4) - throw new GridRedisGenericException("Wrong number of arguments"); - - int offset; - try { - offset = Integer.parseInt(msg.aux(OFFSET_POS)); - } - catch (NumberFormatException e) { - throw new GridRedisGenericException("Offset is not an integer!"); - } - - String val = String.valueOf(msg.aux(VAL_POS)); - - GridRestCacheRequest getReq = new GridRestCacheRequest(); - - getReq.clientId(msg.clientId()); - getReq.key(msg.key()); - getReq.command(CACHE_GET); - - if (val.length() == 0) - return getReq; - - Object resp = hnd.handle(getReq).getResponse(); - - int totalLen = offset + val.length(); - if (offset < 0 || totalLen > 536870911) - throw new GridRedisGenericException("Offset is out of range!"); - - GridRestCacheRequest putReq = new GridRestCacheRequest(); - - putReq.clientId(msg.clientId()); - putReq.key(msg.key()); - putReq.command(CACHE_PUT); - - if (resp == null) { - byte[] dst = new byte[totalLen]; - System.arraycopy(val.getBytes(), 0, dst, offset, val.length()); - - putReq.value(new String(dst)); - } - else { - String cacheVal = String.valueOf(resp); - - cacheVal = cacheVal.substring(0, offset) + val; - - putReq.value(cacheVal); - } - - hnd.handle(putReq); - - return getReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - if (restRes.getResponse() == null) - return GridRedisProtocolParser.toInteger("0"); - else { - int resLen = ((String)restRes.getResponse()).length(); - return GridRedisProtocolParser.toInteger(String.valueOf(resLen)); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java deleted file mode 100644 index 5d7632f..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string; - -import java.nio.ByteBuffer; -import java.util.Collection; -import java.util.List; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler; -import org.apache.ignite.internal.processors.rest.GridRestResponse; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser; -import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisThruRestCommandHandler; -import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest; -import org.apache.ignite.internal.processors.rest.request.GridRestRequest; -import org.apache.ignite.internal.util.typedef.internal.U; - -import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET; -import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.STRLEN; - -/** - * Redis STRLEN command handler. - */ -public class GridRedisStrlenCommandHandler extends GridRedisThruRestCommandHandler { - /** Supported commands. */ - private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList( - STRLEN - ); - - /** {@inheritDoc} */ - public GridRedisStrlenCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) { - super(ctx, hnd); - } - - /** {@inheritDoc} */ - @Override public Collection<GridRedisCommand> supportedCommands() { - return SUPPORTED_COMMANDS; - } - - /** {@inheritDoc} */ - @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException { - assert msg != null; - - GridRestCacheRequest restReq = new GridRestCacheRequest(); - - restReq.clientId(msg.clientId()); - restReq.key(msg.key()); - - restReq.command(CACHE_GET); - - return restReq; - } - - /** {@inheritDoc} */ - @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) { - if (restRes.getResponse() == null) - return GridRedisProtocolParser.toInteger("0"); - else { - int len = String.valueOf(restRes.getResponse()).length(); - return GridRedisProtocolParser.toInteger(String.valueOf(len)); - } - } -}
