com.hazelcast.client.cp.internal.CPSubsystemImpl Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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 com.hazelcast.client.cp.internal;
import com.hazelcast.client.cp.internal.datastructures.proxy.ClientRaftProxyFactory;
import com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl;
import com.hazelcast.client.impl.spi.ClientContext;
import com.hazelcast.cp.IAtomicLong;
import com.hazelcast.cp.IAtomicReference;
import com.hazelcast.cp.ICountDownLatch;
import com.hazelcast.cp.ISemaphore;
import com.hazelcast.cp.CPMember;
import com.hazelcast.cp.CPSubsystem;
import com.hazelcast.cp.CPSubsystemManagementService;
import com.hazelcast.cp.internal.datastructures.atomiclong.AtomicLongService;
import com.hazelcast.cp.internal.datastructures.atomicref.AtomicRefService;
import com.hazelcast.cp.internal.datastructures.countdownlatch.CountDownLatchService;
import com.hazelcast.cp.internal.datastructures.lock.LockService;
import com.hazelcast.cp.internal.datastructures.semaphore.SemaphoreService;
import com.hazelcast.cp.lock.FencedLock;
import com.hazelcast.cp.session.CPSessionManagementService;
import javax.annotation.Nonnull;
import static com.hazelcast.internal.util.Preconditions.checkNotNull;
/**
* Client-side impl of the CP subsystem to create CP data structure proxies
*/
public class CPSubsystemImpl implements CPSubsystem {
private final ClientRaftProxyFactory proxyFactory;
public CPSubsystemImpl(HazelcastClientInstanceImpl client) {
this.proxyFactory = new ClientRaftProxyFactory(client);
}
public void init(ClientContext context) {
proxyFactory.init(context);
}
@Nonnull
@Override
public IAtomicLong getAtomicLong(@Nonnull String name) {
checkNotNull(name, "Retrieving an atomic long instance with a null name is not allowed!");
return proxyFactory.createProxy(AtomicLongService.SERVICE_NAME, name);
}
@Nonnull
@Override
public IAtomicReference getAtomicReference(@Nonnull String name) {
checkNotNull(name, "Retrieving an atomic reference instance with a null name is not allowed!");
return proxyFactory.createProxy(AtomicRefService.SERVICE_NAME, name);
}
@Nonnull
@Override
public ICountDownLatch getCountDownLatch(@Nonnull String name) {
checkNotNull(name, "Retrieving a count down latch instance with a null name is not allowed!");
return proxyFactory.createProxy(CountDownLatchService.SERVICE_NAME, name);
}
@Nonnull
@Override
public FencedLock getLock(@Nonnull String name) {
checkNotNull(name, "Retrieving an fenced lock instance with a null name is not allowed!");
return proxyFactory.createProxy(LockService.SERVICE_NAME, name);
}
@Nonnull
@Override
public ISemaphore getSemaphore(@Nonnull String name) {
checkNotNull(name, "Retrieving a semaphore instance with a null name is not allowed!");
return proxyFactory.createProxy(SemaphoreService.SERVICE_NAME, name);
}
@Override
public CPMember getLocalCPMember() {
throw new UnsupportedOperationException();
}
@Override
public CPSubsystemManagementService getCPSubsystemManagementService() {
throw new UnsupportedOperationException();
}
@Override
public CPSessionManagementService getCPSessionManagementService() {
throw new UnsupportedOperationException();
}
}