PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/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
17package com.hazelcast.client;
18
19import com.hazelcast.core.IdGenerator;
20import com.hazelcast.core.Prefix;
21import com.hazelcast.impl.ClusterOperation;
22
23public class IdGeneratorClientProxy implements IdGenerator {
24    private final String name;
25    private final ProxyHelper proxyHelper;
26
27    public IdGeneratorClientProxy(HazelcastClient hazelcastClient, String name) {
28        this.name = name;
29        proxyHelper = new ProxyHelper(name, hazelcastClient);
30    }
31
32    public String getName() {
33        return name.substring(Prefix.IDGEN.length());
34    }
35
36    public long newId() {
37        return (Long) proxyHelper.doOp(ClusterOperation.NEW_ID, null, null);
38    }
39
40    public InstanceType getInstanceType() {
41        return InstanceType.ID_GENERATOR;
42    }
43
44    public void destroy() {
45        proxyHelper.destroy();
46    }
47
48    public Object getId() {
49        return name;
50    }
51}