Search in sources :

Example 1 with OCallable

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();
        }
    }
}
Also used : OResultSet(com.orientechnologies.orient.core.sql.query.OResultSet) OCallable(com.orientechnologies.common.util.OCallable) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Map(java.util.Map) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OCallable

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;
            }
        });
    }
}
Also used : OCallable(com.orientechnologies.common.util.OCallable) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OLiveResultListener(com.orientechnologies.orient.core.sql.query.OLiveResultListener) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 3 with OCallable

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);
}
Also used : OCallable(com.orientechnologies.common.util.OCallable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OCallable

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);
        }
    }
}
Also used : OCallable(com.orientechnologies.common.util.OCallable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OCallable

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);
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OCallable(com.orientechnologies.common.util.OCallable) OServerCommandGetStaticContent(com.orientechnologies.orient.server.network.protocol.http.command.get.OServerCommandGetStaticContent) OServerNetworkListener(com.orientechnologies.orient.server.network.OServerNetworkListener) URL(java.net.URL)

Aggregations

OCallable (com.orientechnologies.common.util.OCallable)16 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)7 OException (com.orientechnologies.common.exception.OException)7 OIOException (com.orientechnologies.common.io.OIOException)6 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 HazelcastException (com.hazelcast.core.HazelcastException)5 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)5 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)5 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 ORecordId (com.orientechnologies.orient.core.id.ORecordId)4 Callable (java.util.concurrent.Callable)4 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)3 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 OServerCommandGetStaticContent (com.orientechnologies.orient.server.network.protocol.http.command.get.OServerCommandGetStaticContent)2 IOException (java.io.IOException)2 URL (java.net.URL)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OPair (com.orientechnologies.common.util.OPair)1