Search in sources :

Example 1 with ServerConnection

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;
    }
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 2 with ServerConnection

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];
}
Also used : AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 3 with ServerConnection

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);
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 4 with ServerConnection

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);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) CancelCriterion(org.apache.geode.CancelCriterion) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 5 with ServerConnection

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;
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection)

Aggregations

ServerConnection (org.apache.geode.internal.cache.tier.sockets.ServerConnection)5 CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)3 InternalCache (org.apache.geode.internal.cache.InternalCache)3 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)3 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)3 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)3 CancelCriterion (org.apache.geode.CancelCriterion)1 CacheClientNotifier (org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)1 Message (org.apache.geode.internal.cache.tier.sockets.Message)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Test (org.junit.Test)1