Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Copyright (C) GridGain Systems. 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 org.gridgain.client.impl.connection;
import org.gridgain.client.*;
import org.gridgain.client.impl.*;
import org.jetbrains.annotations.*;
import javax.net.ssl.*;
import java.net.*;
import java.util.*;
import static org.gridgain.client.impl.connection.GridClientConnectionCloseReason.*;
/**
* Facade for all possible network communications between client and server. Introduced to hide
* protocol implementation (TCP, HTTP) from client code.
*/
public abstract class GridClientConnection {
/** Topology */
protected GridClientTopology top;
/** Client id. */
protected final UUID clientId;
/** Server address this connection connected to */
private InetSocketAddress srvAddr;
/** SSL context to use if ssl is enabled. */
private SSLContext sslCtx;
/** Client credentials. */
private Object cred;
/**
* Creates a facade.
*
* @param clientId Client identifier.
* @param srvAddr Server address this connection connected to.
* @param sslCtx SSL context to use if SSL is enabled, {@code null} otherwise.
* @param top Topology.
* @param cred Client credentials.
*/
protected GridClientConnection(UUID clientId, InetSocketAddress srvAddr, SSLContext sslCtx, GridClientTopology top,
Object cred) {
assert top != null;
this.clientId = clientId;
this.srvAddr = srvAddr;
this.top = top;
this.sslCtx = sslCtx;
this.cred = cred;
}
/**
* Closes connection facade.
*
* @param reason Why this connection should be closed.
* @param waitCompletion If {@code true} this method will wait until all pending requests are handled.
*/
abstract void close(GridClientConnectionCloseReason reason, boolean waitCompletion);
/**
* Closes connection facade if no requests are in progress.
*
* @param idleTimeout Idle timeout.
* @return {@code True} if no requests were in progress and client was closed, {@code false} otherwise.
*/
abstract boolean closeIfIdle(long idleTimeout);
/**
* Gets server address this connection connected to.
*
* @return Server address this connection connected to.
*/
public InetSocketAddress serverAddress() {
return srvAddr;
}
/**
* Encodes cache flags to bit map.
*
* @param flagSet Set of flags to be encoded.
* @return Bit map.
*/
public static int encodeCacheFlags(Collection flagSet) {
int bits = 0;
if (flagSet.contains(GridClientCacheFlag.SKIP_STORE))
bits |= 1;
if (flagSet.contains(GridClientCacheFlag.SKIP_SWAP))
bits |= 1 << 1;
if (flagSet.contains(GridClientCacheFlag.SYNC_COMMIT))
bits |= 1 << 2;
if (flagSet.contains(GridClientCacheFlag.INVALIDATE))
bits |= 1 << 4;
return bits;
}
/**
* Puts key-value pair into cache.
*
* @param cacheName Cache name.
* @param key Key.
* @param val Value.
* @param flags Cache flags to be enabled.
* @param destNodeId Destination node ID.
* @return If value was actually put.
* @throws GridClientConnectionResetException In case of error.
* @throws GridClientClosedException If client was manually closed before request was sent over network.
*/
public GridClientFutureAdapter cachePut(String cacheName, K key, V val,
Set flags, UUID destNodeId)
throws GridClientConnectionResetException, GridClientClosedException {
return cachePutAll(cacheName, Collections.singletonMap(key, val), flags, destNodeId);
}
/**
* Gets entry from the cache for specified key.
*
* @param cacheName Cache name.
* @param key Key.
* @param flags Cache flags to be enabled.
* @param destNodeId Destination node ID.
* @return Value.
* @throws GridClientConnectionResetException In case of error.
* @throws GridClientClosedException If client was manually closed before request was sent over network.
*/
public GridClientFutureAdapter cacheGet(String cacheName, final K key, Set flags,
UUID destNodeId) throws GridClientConnectionResetException, GridClientClosedException {
final GridClientFutureAdapter