Search in sources :

Example 1 with JobList

use of org.cristalise.kernel.entity.agent.JobList in project kernel by cristal-ise.

the class ClusterStorageManager method get.

/**
 * Internal get method. Retrieves clusters from ClusterStorages & maintains the memory cache.
 * <br>
 * There is a special case for Viewpoint. When path ends with /data it returns referenced Outcome instead of Viewpoint.
 *
 * @param itemPath current Iten
 * @param path the cluster path
 * @return the C2KObject located by path
 */
public C2KLocalObject get(ItemPath itemPath, String path) throws PersistencyException, ObjectNotFoundException {
    // check cache first
    Map<String, C2KLocalObject> sysKeyMemCache = memoryCache.get(itemPath);
    if (sysKeyMemCache != null) {
        synchronized (sysKeyMemCache) {
            C2KLocalObject obj = sysKeyMemCache.get(path);
            if (obj != null) {
                Logger.msg(7, "ClusterStorageManager.get() - found " + itemPath + "/" + path + " in memcache");
                return obj;
            }
        }
    }
    // special case for Viewpoint- When path ends with /data it returns referenced Outcome instead of Viewpoint
    if (path.startsWith(VIEWPOINT.getName()) && path.endsWith("/data")) {
        StringTokenizer tok = new StringTokenizer(path, "/");
        if (tok.countTokens() == 4) {
            // to not catch viewpoints called 'data'
            Viewpoint view = (Viewpoint) get(itemPath, path.substring(0, path.lastIndexOf("/")));
            if (view != null)
                return view.getOutcome();
            else
                return null;
        }
    }
    C2KLocalObject result = null;
    // deal out top level remote maps
    if (path.indexOf('/') == -1) {
        if (path.equals(HISTORY.getName())) {
            result = new History(itemPath, null);
        } else if (path.equals(JOB.getName())) {
            if (itemPath instanceof AgentPath)
                result = new JobList((AgentPath) itemPath, null);
            else
                throw new ObjectNotFoundException("Items do not have job lists");
        }
    }
    if (result == null) {
        // else try each reader in turn until we find it
        ArrayList<ClusterStorage> readers = findStorages(ClusterStorage.getClusterType(path), false);
        for (ClusterStorage thisReader : readers) {
            try {
                result = thisReader.get(itemPath, path);
                Logger.msg(7, "ClusterStorageManager.get() - reading " + path + " from " + thisReader.getName() + " for item " + itemPath);
                // got it!
                if (result != null)
                    break;
            } catch (PersistencyException e) {
                Logger.msg(7, "ClusterStorageManager.get() - reader " + thisReader.getName() + " could not retrieve " + itemPath + "/" + path + ": " + e.getMessage());
            }
        }
    }
    // No result was found after reading the list of ClusterStorages
    if (result == null) {
        throw new ObjectNotFoundException("ClusterStorageManager.get() - Path " + path + " not found in " + itemPath);
    }
    putInMemoryCache(itemPath, path, result);
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) JobList(org.cristalise.kernel.entity.agent.JobList) History(org.cristalise.kernel.events.History)

Aggregations

StringTokenizer (java.util.StringTokenizer)1 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)1 JobList (org.cristalise.kernel.entity.agent.JobList)1 History (org.cristalise.kernel.events.History)1 AgentPath (org.cristalise.kernel.lookup.AgentPath)1 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)1