PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/impl/ascii/memcache/SetCommandParser.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 66 lines | 45 code | 6 blank | 15 comment | 9 complexity | d5effb95b599d9f0067a849a531a77d2 MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.impl.ascii.memcache;
18
19import com.hazelcast.impl.ascii.TextCommand;
20import com.hazelcast.impl.ascii.TextCommandConstants;
21import com.hazelcast.impl.ascii.TypeAwareCommandParser;
22import com.hazelcast.nio.ascii.SocketTextReader;
23
24import java.util.StringTokenizer;
25
26import static com.hazelcast.impl.ascii.TextCommandConstants.TextCommandType.ERROR_CLIENT;
27
28public class SetCommandParser extends TypeAwareCommandParser {
29    public SetCommandParser(TextCommandConstants.TextCommandType type) {
30        super(type);
31    }
32
33    public TextCommand parser(SocketTextReader socketTextReader, String cmd, int space) {
34        StringTokenizer st = new StringTokenizer(cmd);
35        st.nextToken();
36        String key = null;
37        int valueLen = 0;
38        int flag = 0;
39        int expiration = 0;
40        boolean noReply = false;
41        if (st.hasMoreTokens()) {
42            key = st.nextToken();
43        } else {
44            return new ErrorCommand(ERROR_CLIENT);
45        }
46        if (st.hasMoreTokens()) {
47            flag = Integer.valueOf(st.nextToken());
48        } else {
49            return new ErrorCommand(ERROR_CLIENT);
50        }
51        if (st.hasMoreTokens()) {
52            expiration = Integer.parseInt(st.nextToken());
53        } else {
54            return new ErrorCommand(ERROR_CLIENT);
55        }
56        if (st.hasMoreTokens()) {
57            valueLen = Integer.parseInt(st.nextToken());
58        } else {
59            return new ErrorCommand(ERROR_CLIENT);
60        }
61        if (st.hasMoreTokens()) {
62            noReply = "noreply".equals(st.nextToken());
63        }
64        return new SetCommand(type, key, flag, expiration, valueLen, noReply);
65    }
66}