Search in sources :

Example 1 with ServerInformationRetrievalThread

use of com.emc.metalnx.services.machine.util.ServerInformationRetrievalThread in project metalnx-web by irods-contrib.

the class ServerServiceImpl method initServerThreads.

/**
 *****************************************************************************************
 */
/* CACHE METHODS */
/**
 *****************************************************************************************
 */
private void initServerThreads(List<DataGridServer> servers) {
    for (DataGridServer server : servers) {
        // Instantiating thread
        ServerInformationRetrievalThread t = new ServerInformationRetrievalThread(server.getHostname(), rmdConnectionPort, ServerRequestInfoType.ALL, Integer.parseInt(rmdConnectionTimeout));
        // Starting thread execution
        t.start();
        // Keeping track of the thread instance
        synchronized (threadList) {
            threadList.add(t);
        }
    }
    synchronized (threadList) {
        for (ServerInformationRetrievalThread t : threadList) {
            try {
                t.join();
                String results = t.getResult();
                if (results == null) {
                    results = "";
                }
                serverInfoCache.put(t.getServerHost(), results);
                cacheTimeToLive.put(t.getServerHost(), System.currentTimeMillis() + 5 * 1000);
            } catch (InterruptedException e) {
                logger.error("Could not get server information on [{}]", t.getServerHost(), e);
            }
        }
    }
    synchronized (threadList) {
        threadList.clear();
    }
}
Also used : DataGridServer(com.emc.metalnx.core.domain.entity.DataGridServer) ServerInformationRetrievalThread(com.emc.metalnx.services.machine.util.ServerInformationRetrievalThread)

Example 2 with ServerInformationRetrievalThread

use of com.emc.metalnx.services.machine.util.ServerInformationRetrievalThread in project metalnx-web by irods-contrib.

the class ServerServiceImpl method getServerInfo.

private String getServerInfo(String hostname) {
    logger.debug("Getting Server Info for [{}]", hostname);
    long currentTime = System.currentTimeMillis();
    if (serverInfoCache.containsKey(hostname) && currentTime < cacheTimeToLive.get(hostname)) {
        logger.debug("Cache hit for [{}]", hostname);
        return serverInfoCache.get(hostname);
    } else if (currentTime > cacheTimeToLive.get(hostname)) {
        // Invalidating entries
        serverInfoCache.remove(hostname);
        cacheTimeToLive.remove(hostname);
    }
    logger.debug("Cache miss for [{}]", hostname);
    logger.info("Getting all metrics from [{}]", hostname);
    ServerInformationRetrievalThread serverInfoThread = new ServerInformationRetrievalThread(hostname, rmdConnectionPort, ServerRequestInfoType.ALL, Integer.parseInt(rmdConnectionTimeout));
    serverInfoThread.start();
    try {
        serverInfoThread.join();
    } catch (InterruptedException e) {
        logger.error("Could not get server information on [{}]", serverInfoThread.getServerHost(), e);
    }
    String results = serverInfoThread.getResult();
    if (results != null) {
        serverInfoCache.put(hostname, results);
        // Settings time to live for entry
        cacheTimeToLive.put(hostname, System.currentTimeMillis() + 5 * 1000);
    }
    return results;
}
Also used : ServerInformationRetrievalThread(com.emc.metalnx.services.machine.util.ServerInformationRetrievalThread)

Aggregations

ServerInformationRetrievalThread (com.emc.metalnx.services.machine.util.ServerInformationRetrievalThread)2 DataGridServer (com.emc.metalnx.core.domain.entity.DataGridServer)1