use of org.apache.synapse.registry.RegistryEntry in project wso2-synapse by wso2.
the class SimpleURLRegistry method getChildren.
public RegistryEntry[] getChildren(RegistryEntry entry) {
URL url;
if (entry == null) {
RegistryEntryImpl entryImpl = new RegistryEntryImpl();
entryImpl.setKey("");
entry = entryImpl;
}
url = SynapseConfigUtils.getURLFromPath(root + entry.getKey(), properties.get(SynapseConstants.SYNAPSE_HOME) != null ? properties.get(SynapseConstants.SYNAPSE_HOME).toString() : "");
if (url == null) {
return null;
}
if (url.getProtocol().equals("file")) {
File file = new File(url.getFile());
if (!file.isDirectory()) {
return null;
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader((InputStream) url.getContent()));
ArrayList<RegistryEntry> entryList = new ArrayList<RegistryEntry>();
String key;
while ((key = reader.readLine()) != null) {
RegistryEntryImpl registryEntryImpl = new RegistryEntryImpl();
if (entry.getKey().equals("")) {
registryEntryImpl.setKey(key);
} else {
if (entry.getKey().endsWith("/")) {
registryEntryImpl.setKey(entry.getKey() + key);
} else {
registryEntryImpl.setKey(entry.getKey() + "/" + key);
}
}
entryList.add(registryEntryImpl);
}
RegistryEntry[] entries = new RegistryEntry[entryList.size()];
for (int i = 0; i < entryList.size(); i++) {
entries[i] = entryList.get(i);
}
return entries;
} catch (Exception e) {
throw new SynapseException("Error in reading the URL.");
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignored) {
}
}
}
} else {
throw new SynapseException("Invalid protocol.");
}
}
use of org.apache.synapse.registry.RegistryEntry in project wso2-synapse by wso2.
the class RegistryResourceFetcher method getResource.
private Object getResource(Entry entry, Properties properties) {
OMNode omNode;
RegistryEntry re = registry.getRegistryEntry(entry.getKey());
omNode = registry.lookup(entry.getKey());
if (re == null) {
return null;
}
if ((!entry.isCached() || (re.getVersion() == Long.MIN_VALUE || re.getVersion() != entry.getVersion())) || re.getLastModified() >= lastExecutionTime) {
entry.setEntryProperties(registry.getResourceProperties(entry.getKey()));
entry.setVersion(re.getVersion());
// if we get here, we have received the raw omNode from the
// registry and our previous copy (if we had one) has expired or is not valid
Object expiredValue = entry.getValue();
// resource into the appropriate object - e.g. sequence or endpoint
if (entry.getMapper() != null) {
entry.setValue(entry.getMapper().getObjectFromOMNode(omNode, properties));
if (entry.getValue() instanceof SequenceMediator) {
SequenceMediator seq = (SequenceMediator) entry.getValue();
seq.setDynamic(true);
seq.setRegistryKey(entry.getKey());
seq.init(synapseEnvironment);
} else if (entry.getValue() instanceof Endpoint) {
Endpoint ep = (Endpoint) entry.getValue();
ep.init(synapseEnvironment);
}
} else {
// if the type of the object is known to have a mapper, create the
// resultant Object using the known mapper, and cache this Object
// else cache the raw OMNode
entry.setValue(omNode);
}
if (expiredValue != null) {
// Destroy the old resource so that everything is properly cleaned up
if (expiredValue instanceof SequenceMediator) {
((SequenceMediator) expiredValue).destroy();
} else if (expiredValue instanceof Endpoint) {
((Endpoint) expiredValue).destroy();
}
}
entry.setVersion(re.getVersion());
}
// new getRegistryEntry() call
if (re.getCachableDuration() > 0) {
entry.setExpiryTime(System.currentTimeMillis() + re.getCachableDuration());
} else {
entry.setExpiryTime(-1);
}
return entry.getValue();
}
Aggregations