/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. package com.hazelcast.impl.ascii.memcache;
  17. import com.hazelcast.impl.ascii.TextCommand;
  18. import com.hazelcast.impl.ascii.TextCommandConstants;
  19. import com.hazelcast.impl.ascii.TypeAwareCommandParser;
  20. import com.hazelcast.nio.ascii.SocketTextReader;
  21. import java.util.StringTokenizer;
  22. import static com.hazelcast.impl.ascii.TextCommandConstants.TextCommandType.ERROR_CLIENT;
  23. public class SetCommandParser extends TypeAwareCommandParser {
  24. public SetCommandParser(TextCommandConstants.TextCommandType type) {
  25. super(type);
  26. }
  27. public TextCommand parser(SocketTextReader socketTextReader, String cmd, int space) {
  28. StringTokenizer st = new StringTokenizer(cmd);
  29. st.nextToken();
  30. String key = null;
  31. int valueLen = 0;
  32. int flag = 0;
  33. int expiration = 0;
  34. boolean noReply = false;
  35. if (st.hasMoreTokens()) {
  36. key = st.nextToken();
  37. } else {
  38. return new ErrorCommand(ERROR_CLIENT);
  39. }
  40. if (st.hasMoreTokens()) {
  41. flag = Integer.valueOf(st.nextToken());
  42. } else {
  43. return new ErrorCommand(ERROR_CLIENT);
  44. }
  45. if (st.hasMoreTokens()) {
  46. expiration = Integer.parseInt(st.nextToken());
  47. } else {
  48. return new ErrorCommand(ERROR_CLIENT);
  49. }
  50. if (st.hasMoreTokens()) {
  51. valueLen = Integer.parseInt(st.nextToken());
  52. } else {
  53. return new ErrorCommand(ERROR_CLIENT);
  54. }
  55. if (st.hasMoreTokens()) {
  56. noReply = "noreply".equals(st.nextToken());
  57. }
  58. return new SetCommand(type, key, flag, expiration, valueLen, noReply);
  59. }
  60. }