/hazelcast-client/src/main/java/com/hazelcast/client/IdGeneratorClientProxy.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 51 lines · 27 code · 9 blank · 15 comment · 0 complexity · b3ceea79956c96ef6962eeb2eade6ca4 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.client;
  17. import com.hazelcast.core.IdGenerator;
  18. import com.hazelcast.core.Prefix;
  19. import com.hazelcast.impl.ClusterOperation;
  20. public class IdGeneratorClientProxy implements IdGenerator {
  21. private final String name;
  22. private final ProxyHelper proxyHelper;
  23. public IdGeneratorClientProxy(HazelcastClient hazelcastClient, String name) {
  24. this.name = name;
  25. proxyHelper = new ProxyHelper(name, hazelcastClient);
  26. }
  27. public String getName() {
  28. return name.substring(Prefix.IDGEN.length());
  29. }
  30. public long newId() {
  31. return (Long) proxyHelper.doOp(ClusterOperation.NEW_ID, null, null);
  32. }
  33. public InstanceType getInstanceType() {
  34. return InstanceType.ID_GENERATOR;
  35. }
  36. public void destroy() {
  37. proxyHelper.destroy();
  38. }
  39. public Object getId() {
  40. return name;
  41. }
  42. }