use of org.cristalise.kernel.common.ObjectNotFoundException 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;
}
use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.
the class DescriptionObjectCache method get.
public D get(String name, int version) throws ObjectNotFoundException, InvalidDataException {
D thisDef = null;
synchronized (cache) {
CacheEntry<D> thisDefEntry = cache.get(name + "_" + version);
if (thisDefEntry == null) {
Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " not found in cache. Checking id.");
try {
ItemPath defItemPath = findItem(name);
String defId = defItemPath.getUUID().toString();
thisDefEntry = cache.get(defId + "_" + version);
if (thisDefEntry == null) {
Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " not found in cache. Loading from database.");
ItemProxy defItemProxy = Gateway.getProxyManager().getProxy(defItemPath);
if (name.equals(defId)) {
String itemName = defItemProxy.getName();
if (itemName != null)
name = itemName;
}
thisDef = loadObject(name, version, defItemProxy);
cache.put(defId + "_" + version, new CacheEntry<D>(thisDef, defItemProxy, this));
}
} catch (ObjectNotFoundException ex) {
// for bootstrap and testing, try to load built-in kernel objects from resources
if (version == 0) {
try {
return loadObjectFromBootstrap(name);
} catch (ObjectNotFoundException ex2) {
}
}
throw ex;
}
}
if (thisDefEntry != null && thisDef == null) {
Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " found in cache.");
thisDef = thisDefEntry.def;
}
}
return thisDef;
}
use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.
the class DescriptionObjectCache method loadObject.
public D loadObject(String name, int version, ItemProxy proxy) throws ObjectNotFoundException, InvalidDataException {
Viewpoint smView = (Viewpoint) proxy.getObject(ClusterType.VIEWPOINT + "/" + getSchemaName() + "/" + version);
String rawRes;
try {
rawRes = smView.getOutcome().getData();
} catch (PersistencyException ex) {
Logger.error(ex);
throw new ObjectNotFoundException("Problem loading " + getSchemaName() + " " + name + " v" + version + ": " + ex.getMessage());
}
return buildObject(name, version, proxy.getPath(), rawRes);
}
use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.
the class ProxyLoader method get.
/**
* retrieve object by path
*/
@Override
public C2KLocalObject get(ItemPath thisItem, String path) throws PersistencyException {
try {
Item thisEntity = getIOR(thisItem);
ClusterType type = getClusterType(path);
// fetch the xml from the item
String queryData = thisEntity.queryData(path);
if (Logger.doLog(8))
Logger.msg("ProxyLoader.get() - " + thisItem + " : " + path + " = " + queryData);
if (queryData != null) {
if (type == ClusterType.OUTCOME)
return new Outcome(path, queryData);
else
return (C2KLocalObject) Gateway.getMarshaller().unmarshall(queryData);
}
} catch (ObjectNotFoundException e) {
return null;
} catch (Exception e) {
Logger.error(e);
throw new PersistencyException(e.getMessage());
}
return null;
}
use of org.cristalise.kernel.common.ObjectNotFoundException in project kernel by cristal-ise.
the class RemoveDomainContext method runActivityLogic.
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
String[] params = getDataList(requestData);
Logger.msg(3, "RemoveDomainContext: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
if (params.length != 1)
throw new InvalidDataException("RemoveDomainContext: Invalid parameters " + Arrays.toString(params));
DomainPath pathToDelete = new DomainPath(params[0]);
if (!pathToDelete.exists())
throw new ObjectNotFoundException("Context " + pathToDelete + " does not exist");
try {
pathToDelete.getItemPath();
throw new InvalidDataException("Path " + pathToDelete + " is an Entity. Use its own Erase step instead, or RemoveAgent.");
} catch (ObjectNotFoundException ex) {
}
if (Gateway.getLookup().getChildren(pathToDelete).hasNext())
throw new ObjectCannotBeUpdated("Context " + pathToDelete + " is not empty. Cannot delete.");
Gateway.getLookupManager().delete(pathToDelete);
return requestData;
}
Aggregations