Search in sources :

Example 41 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class InternalDistributedSystem method createAndStartCacheServers.

/**
   * after an auto-reconnect we may need to recreate a cache server and start it
   */
public void createAndStartCacheServers(List<CacheServerCreation> cacheServerCreation, InternalCache cache) {
    List<CacheServer> servers = cache.getCacheServers();
    // to recreate it.
    if (servers.isEmpty() && cacheServerCreation != null) {
        for (CacheServerCreation bridge : cacheServerCreation) {
            CacheServerImpl impl = (CacheServerImpl) cache.addCacheServer();
            impl.configureFrom(bridge);
        }
    }
    servers = cache.getCacheServers();
    for (CacheServer server : servers) {
        try {
            if (!server.isRunning()) {
                server.start();
            }
        } catch (IOException ex) {
            throw new GemFireIOException(LocalizedStrings.CacheCreation_WHILE_STARTING_CACHE_SERVER_0.toLocalizedString(server), ex);
        }
    }
}
Also used : CacheServerCreation(org.apache.geode.internal.cache.xmlcache.CacheServerCreation) CacheServer(org.apache.geode.cache.server.CacheServer) GemFireIOException(org.apache.geode.GemFireIOException) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException)

Example 42 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class InternalClientMembership method getConnectedClients.

/**
   * Returns a map of client memberIds to count of connections to that client. The map entry key is
   * a String representation of the client memberId, and the map entry value is an Integer count of
   * connections to that client. Since a single client can have multiple ConnectionProxy objects,
   * this map will contain all the Connection objects across the ConnectionProxies
   * 
   * @param onlyClientsNotifiedByThisServer true will return only those clients that are actively
   *        being updated by this server
   * @return map of client memberIds to count of connections to that client
   * 
   * 
   */
public static Map getConnectedClients(boolean onlyClientsNotifiedByThisServer) {
    ClientHealthMonitor chMon = ClientHealthMonitor.getInstance();
    Set filterProxyIDs = null;
    if (onlyClientsNotifiedByThisServer) {
        // since this is only a status (snapshot) of the system.
        for (Iterator bsii = CacheFactory.getAnyInstance().getCacheServers().iterator(); bsii.hasNext(); ) {
            CacheServerImpl bsi = (CacheServerImpl) bsii.next();
            AcceptorImpl ai = bsi.getAcceptor();
            if (ai != null && ai.getCacheClientNotifier() != null) {
                if (filterProxyIDs != null) {
                    // notifierClients is a copy set from CacheClientNotifier
                    filterProxyIDs.addAll(ai.getCacheClientNotifier().getActiveClients());
                } else {
                    // notifierClients is a copy set from CacheClientNotifier
                    filterProxyIDs = ai.getCacheClientNotifier().getActiveClients();
                }
            }
        }
    }
    Map map = chMon.getConnectedClients(filterProxyIDs);
    /*
     * if (onlyClientsNotifiedByThisServer) { Map notifyMap = new HashMap();
     * 
     * for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { String memberId = (String)
     * iter.next(); if (notifierClients.contains(memberId)) { // found memberId that is notified by
     * this server notifyMap.put(memberId, map.get(memberId)); } } map = notifyMap; }
     */
    return map;
}
Also used : Set(java.util.Set) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) ClientHealthMonitor(org.apache.geode.internal.cache.tier.sockets.ClientHealthMonitor) Iterator(java.util.Iterator) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 43 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl 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 44 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl 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 45 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl 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)

Aggregations

CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)76 Iterator (java.util.Iterator)23 Cache (org.apache.geode.cache.Cache)19 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)19 CacheServer (org.apache.geode.cache.server.CacheServer)14 IOException (java.io.IOException)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13 CacheException (org.apache.geode.cache.CacheException)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)8 Set (java.util.Set)7 InternalCache (org.apache.geode.internal.cache.InternalCache)7 Map (java.util.Map)6 Properties (java.util.Properties)6 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 HashMap (java.util.HashMap)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 RegionAttributes (org.apache.geode.cache.RegionAttributes)5 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)5