use of org.apache.geode.internal.cache.tier.sockets.ServerConnection in project geode by apache.
the class CacheServerBridge method getClientVersion.
public Version getClientVersion(ClientConnInfo connInfo) {
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
if (cache.getCacheServers().size() == 0) {
return null;
}
CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
if (server == null) {
return null;
}
AcceptorImpl acceptorImpl = server.getAcceptor();
if (acceptorImpl == null) {
return null;
}
ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
boolean flag = false;
if (connInfo.toString().contains("primary=true")) {
flag = true;
}
for (ServerConnection conn : serverConnections) {
ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
ClientConnInfo cci = new ClientConnInfo(conn.getProxyID(), conn.getSocketHost(), conn.getSocketPort(), flag);
if (connInfo.toString().equals(cci.toString())) {
return cliIdFrmProxy.getClientVersion();
}
}
// check form ccp
ClientProxyMembershipID proxyId = connInfo.getClientId();
CacheClientProxy proxy = CacheClientNotifier.getInstance().getClientProxy(proxyId);
if (proxy != null) {
return proxy.getVersion();
} else {
return null;
}
}
use of org.apache.geode.internal.cache.tier.sockets.ServerConnection in project geode by apache.
the class GatewayReceiverMBeanBridge method getConnectedGatewaySenders.
public String[] getConnectedGatewaySenders() {
Set<String> uniqueIds = null;
AcceptorImpl acceptor = ((CacheServerImpl) rcv.getServer()).getAcceptor();
Set<ServerConnection> serverConnections = acceptor.getAllServerConnections();
if (serverConnections != null && serverConnections.size() > 0) {
uniqueIds = new HashSet<String>();
for (ServerConnection conn : serverConnections) {
uniqueIds.add(conn.getMembershipID());
}
String[] allConnectedClientStr = new String[uniqueIds.size()];
return uniqueIds.toArray(allConnectedClientStr);
}
return new String[0];
}
use of org.apache.geode.internal.cache.tier.sockets.ServerConnection in project geode by apache.
the class ContunuousQueryFunction method execute.
@Override
public void execute(FunctionContext context) {
try {
String clientID = (String) context.getArguments();
InternalCache cache = getCache();
if (cache.getCacheServers().size() > 0) {
CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
if (server != null) {
AcceptorImpl acceptorImpl = server.getAcceptor();
if (acceptorImpl != null) {
CacheClientNotifier cacheClientNotifier = acceptorImpl.getCacheClientNotifier();
if (cacheClientNotifier != null) {
Collection<CacheClientProxy> cacheClientProxySet = cacheClientNotifier.getClientProxies();
ClientInfo clientInfo = null;
boolean foundClientinCCP = false;
Iterator<CacheClientProxy> it = cacheClientProxySet.iterator();
while (it.hasNext()) {
CacheClientProxy ccp = it.next();
if (ccp != null) {
String clientIdFromProxy = ccp.getProxyID().getDSMembership();
if (clientIdFromProxy != null && clientIdFromProxy.equals(clientID)) {
foundClientinCCP = true;
String durableId = ccp.getProxyID().getDurableId();
boolean isPrimary = ccp.isPrimary();
clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), (isPrimary == true ? cache.getDistributedSystem().getDistributedMember().getId() : ""), (isPrimary == false ? cache.getDistributedSystem().getDistributedMember().getId() : ""));
break;
}
}
}
// try getting from server connections
if (foundClientinCCP == false) {
ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
for (ServerConnection conn : serverConnections) {
ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
if (clientID.equals(cliIdFrmProxy.getDSMembership())) {
String durableId = cliIdFrmProxy.getDurableId();
clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), "N.A.", "N.A.");
}
}
}
context.getResultSender().lastResult(clientInfo);
}
}
}
}
} catch (Exception e) {
context.getResultSender().lastResult("Exception in ContunuousQueryFunction =" + e.getMessage());
}
context.getResultSender().lastResult(null);
}
use of org.apache.geode.internal.cache.tier.sockets.ServerConnection in project geode by apache.
the class CommitCommandTest method testWriteNullResponse.
/**
* Test for GEODE-537 No NPE should be thrown from the
* {@link CommitCommand#writeCommitResponse(org.apache.geode.internal.cache.TXCommitMessage, Message, ServerConnection)}
* if the response message is null as it is the case when JTA transaction is rolled back with
* TX_SYNCHRONIZATION AFTER_COMPLETION STATUS_ROLLEDBACK
*/
@Test
public void testWriteNullResponse() throws Exception {
InternalCache cache = mock(InternalCache.class);
Message origMsg = mock(Message.class);
ServerConnection servConn = mock(ServerConnection.class);
when(servConn.getResponseMessage()).thenReturn(mock(Message.class));
when(servConn.getCache()).thenReturn(cache);
when(cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class));
CommitCommand.writeCommitResponse(null, origMsg, servConn);
}
use of org.apache.geode.internal.cache.tier.sockets.ServerConnection in project geode by apache.
the class CacheServerBridge method getUniqueClientIds.
private Map<String, ClientConnInfo> getUniqueClientIds() {
Map<String, ClientConnInfo> uniqueIds = null;
ServerConnection[] serverConnections = acceptor.getAllServerConnectionList();
Collection<CacheClientProxy> clientProxies = acceptor.getCacheClientNotifier().getClientProxies();
if (clientProxies.size() > 0) {
uniqueIds = new HashMap<String, ClientConnInfo>();
for (CacheClientProxy p : clientProxies) {
ClientConnInfo clientConInfo = new ClientConnInfo(p.getProxyID(), p.getSocketHost(), p.getRemotePort(), p.isPrimary());
uniqueIds.put(p.getProxyID().getDSMembership(), clientConInfo);
}
}
if (serverConnections != null && serverConnections.length > 0) {
if (uniqueIds == null) {
uniqueIds = new HashMap<String, ClientConnInfo>();
}
for (ServerConnection conn : serverConnections) {
ClientProxyMembershipID clientId = conn.getProxyID();
if (clientId != null) {
// Check added to fix bug 51987
if (uniqueIds.get(clientId.getDSMembership()) == null) {
ClientConnInfo clientConInfo = new ClientConnInfo(conn.getProxyID(), conn.getSocketHost(), conn.getSocketPort(), false);
uniqueIds.put(clientId.getDSMembership(), clientConInfo);
}
}
}
}
if (uniqueIds == null) {
return Collections.emptyMap();
}
return uniqueIds;
}
Aggregations