use of com.orientechnologies.common.util.OCallable in project orientdb by orientechnologies.
the class OCommandExecutorSQLLiveSelect method execute.
public Object execute(final Map<Object, Object> iArgs) {
try {
final ODatabaseDocumentInternal db = getDatabase();
execInSeparateDatabase(new OCallable() {
@Override
public Object call(Object iArgument) {
return execDb = ((ODatabaseDocumentTx) db).copy();
}
});
synchronized (random) {
// TODO do something better ;-)!
token = random.nextInt();
}
subscribeToLiveQuery(token, db);
bindDefaultContextVariables();
if (iArgs != null) // BIND ARGUMENTS INTO CONTEXT TO ACCESS FROM ANY POINT (EVEN FUNCTIONS)
{
for (Map.Entry<Object, Object> arg : iArgs.entrySet()) {
context.setVariable(arg.getKey().toString(), arg.getValue());
}
}
if (timeoutMs > 0) {
getContext().beginExecution(timeoutMs, timeoutStrategy);
}
ODocument result = new ODocument();
// TODO change this name...?
result.field("token", token);
((OResultSet) getResult()).add(result);
return getResult();
} finally {
if (request != null && request.getResultListener() != null) {
request.getResultListener().end();
}
}
}
use of com.orientechnologies.common.util.OCallable in project orientdb by orientechnologies.
the class OCommandExecutorSQLLiveSelect method onLiveResult.
public void onLiveResult(final ORecordOperation iOp) {
ODatabaseDocumentInternal oldThreadLocal = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
execDb.activateOnCurrentThread();
try {
final OIdentifiable value = iOp.getRecord();
if (!matchesTarget(value)) {
return;
}
if (!matchesFilters(value)) {
return;
}
if (!checkSecurity(value)) {
return;
}
} finally {
if (oldThreadLocal == null) {
ODatabaseRecordThreadLocal.INSTANCE.remove();
} else {
ODatabaseRecordThreadLocal.INSTANCE.set(oldThreadLocal);
}
}
final OCommandResultListener listener = request.getResultListener();
if (listener instanceof OLiveResultListener) {
execInSeparateDatabase(new OCallable() {
@Override
public Object call(Object iArgument) {
execDb.activateOnCurrentThread();
((OLiveResultListener) listener).onLiveResult(token, iOp);
return null;
}
});
}
}
use of com.orientechnologies.common.util.OCallable in project orientdb by orientechnologies.
the class OCRUDWorkload method createOperation.
public ODocument createOperation(final long n) {
return (ODocument) ODatabaseDocumentTx.executeWithRetries(new OCallable<Object, Integer>() {
@Override
public Object call(Integer iArgument) {
ODocument doc = new ODocument(CLASS_NAME);
doc.field("name", "value" + n);
doc.save();
return doc;
}
}, 10);
}
use of com.orientechnologies.common.util.OCallable in project orientdb by orientechnologies.
the class OFunctionLibraryImpl method load.
public void load() {
// COPY CALLBACK IN RAM
final Map<String, OCallable<Object, Map<Object, Object>>> callbacks = new HashMap<String, OCallable<Object, Map<Object, Object>>>();
for (Map.Entry<String, OFunction> entry : functions.entrySet()) {
if (entry.getValue().getCallback() != null)
callbacks.put(entry.getKey(), entry.getValue().getCallback());
}
functions.clear();
// LOAD ALL THE FUNCTIONS IN MEMORY
final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
if (((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot().existsClass("OFunction")) {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from OFunction order by name"));
for (ODocument d : result) {
d.reload();
// skip the function records which do not contain real data
if (d.fields() == 0)
continue;
final OFunction f = new OFunction(d);
// RESTORE CALLBACK IF ANY
f.setCallback(callbacks.get(f.getName()));
functions.put(d.field("name").toString().toUpperCase(Locale.ENGLISH), f);
}
}
}
use of com.orientechnologies.common.util.OCallable in project orientdb by orientechnologies.
the class OServerPluginManager method registerStaticDirectory.
protected void registerStaticDirectory(final OServerPluginInfo iPluginData) {
Object pluginWWW = iPluginData.getParameter("www");
if (pluginWWW == null)
pluginWWW = iPluginData.getName();
final OServerNetworkListener httpListener = server.getListenerByProtocol(ONetworkProtocolHttpAbstract.class);
if (httpListener == null)
throw new OConfigurationException("HTTP listener not registered while installing Static Content command");
final OServerCommandGetStaticContent command = (OServerCommandGetStaticContent) httpListener.getCommand(OServerCommandGetStaticContent.class);
if (command != null) {
final URL wwwURL = iPluginData.getClassLoader().findResource("www/");
final OCallable<Object, String> callback;
if (wwwURL != null)
callback = createStaticLinkCallback(iPluginData, wwwURL);
else
// LET TO THE COMMAND TO CONTROL IT
callback = new OCallable<Object, String>() {
@Override
public Object call(final String iArgument) {
return iPluginData.getInstance().getContent(iArgument);
}
};
command.registerVirtualFolder(pluginWWW.toString(), callback);
}
}
Aggregations