Search in sources :

Example 6 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class PutAllOp method constructAndGetPutAllTasks.

static List constructAndGetPutAllTasks(Region region, final Map map, final EventID eventId, boolean skipCallbacks, final Map<ServerLocation, HashSet> serverToFilterMap, final PoolImpl pool, Object callbackArg) {
    final List<SingleHopOperationCallable> tasks = new ArrayList<SingleHopOperationCallable>();
    ArrayList<ServerLocation> servers = new ArrayList<ServerLocation>(serverToFilterMap.keySet());
    if (logger.isDebugEnabled()) {
        logger.debug("Constructing tasks for the servers {}", servers);
    }
    for (ServerLocation server : servers) {
        Set filterSet = serverToFilterMap.get(server);
        Map newKeysValuesMap = new LinkedHashMap();
        // iterator 1: for single hop, both iterator filterSet and newKeysValuesMap
        for (Object key : filterSet) {
            newKeysValuesMap.put(key, map.get(key));
        }
        AbstractOp putAllOp = new PutAllOpImpl(region, newKeysValuesMap, eventId, true, skipCallbacks, callbackArg);
        SingleHopOperationCallable task = new SingleHopOperationCallable(new ServerLocation(server.getHostName(), server.getPort()), pool, putAllOp, UserAttributes.userAttributes.get());
        tasks.add(task);
    }
    return tasks;
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class QueueManagerImpl method start.

public void start(ScheduledExecutorService background) {
    try {
        blackList.start(background);
        endpointManager.addListener(endpointListener);
        // Use a separate timer for queue management tasks
        // We don't want primary recovery (and therefore user threads) to wait for
        // things like pinging connections for health checks.
        // this.background = background;
        final String name = "queueTimer-" + this.pool.getName();
        this.recoveryThread = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {

            public Thread newThread(Runnable r) {
                Thread result = new Thread(r, name);
                result.setDaemon(true);
                return result;
            }
        });
        recoveryThread.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
        // TODO - use yet another Timer or the like for these tasks? We know
        // we don't want them in the recoveryThread, because the ThreadIdToSequenceIdExpiryTask
        // will wait for primary recovery.
        getState().start(background, getPool().getSubscriptionAckInterval());
        // initialize connections
        initializeConnections();
        scheduleRedundancySatisfierIfNeeded(redundancyRetryInterval);
        // When a server is removed from the blacklist, try again
        // to establish redundancy (if we need to)
        BlackListListener blackListListener = new BlackListListenerAdapter() {

            @Override
            public void serverRemoved(ServerLocation location) {
                QueueManagerImpl.this.scheduleRedundancySatisfierIfNeeded(0);
            }
        };
        blackList.addListener(blackListListener);
        factory.getBlackList().addListener(blackListListener);
    } finally {
        initializedLatch.countDown();
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) BlackListListener(org.apache.geode.cache.client.internal.ServerBlackList.BlackListListener) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) BlackListListenerAdapter(org.apache.geode.cache.client.internal.ServerBlackList.BlackListListenerAdapter)

Example 8 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class PoolImpl method getRedundantNames.

/**
   * Test hook that returns a list of strings. Each string consists of the host name and port of a
   * redundant server. An empty list is returned if we have no redundant servers.
   */
public List<String> getRedundantNames() {
    List result = Collections.emptyList();
    if (this.queueManager != null) {
        QueueManager.QueueConnections cons = this.queueManager.getAllConnections();
        List<Connection> backupCons = cons.getBackups();
        if (backupCons.size() > 0) {
            result = new ArrayList(backupCons.size());
            Iterator<Connection> it = backupCons.iterator();
            while (it.hasNext()) {
                Connection con = it.next();
                ServerLocation sl = con.getServer();
                result.add(sl.getHostName() + sl.getPort());
            }
        }
    }
    return result;
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class PoolImpl method getCurrentServerNames.

/**
   * Test hook that returns a list of server names (host+port); one for each server we are currently
   * connected to.
   */
public List<String> getCurrentServerNames() {
    List<ServerLocation> servers = getCurrentServers();
    ArrayList<String> result = new ArrayList(servers.size());
    Iterator it = servers.iterator();
    while (it.hasNext()) {
        ServerLocation sl = (ServerLocation) it.next();
        String name = sl.getHostName() + sl.getPort();
        result.add(name);
    }
    return result;
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 10 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class ProxyCache method close.

public void close(boolean keepAlive) {
    if (this.isClosed) {
        return;
    }
    // them to clean-up its entry from their auth-data structures.
    try {
        if (this.proxyQueryService != null) {
            this.proxyQueryService.closeCqs(keepAlive);
        }
        UserAttributes.userAttributes.set(this.userAttributes);
        for (final ServerLocation serverLocation : this.userAttributes.getServerToId().keySet()) {
            ProxyCacheCloseOp.executeOn(serverLocation, (ExecutablePool) this.userAttributes.getPool(), this.userAttributes.getCredentials(), keepAlive);
        }
        List<ProxyCache> proxyCache = ((PoolImpl) this.userAttributes.getPool()).getProxyCacheList();
        synchronized (proxyCache) {
            proxyCache.remove(this);
        }
    } finally {
        // TODO: I think some NPE will be caused by this code.
        // It would be safer to not null things out.
        // It is really bad that we null out and then set isClosed true.
        this.isClosed = true;
        this.proxyQueryService = null;
        this.userAttributes.setCredentials(null);
        this.userAttributes = null;
        UserAttributes.userAttributes.set(null);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation)

Aggregations

ServerLocation (org.apache.geode.distributed.internal.ServerLocation)95 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)21 HashSet (java.util.HashSet)19 List (java.util.List)18 HashMap (java.util.HashMap)17 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)17 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)13 Map (java.util.Map)12 Iterator (java.util.Iterator)10 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)9 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 Set (java.util.Set)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 LinkedHashSet (java.util.LinkedHashSet)7 Host (org.apache.geode.test.dunit.Host)7 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5