All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nustaq.kontraktor.Scheduler Maven / Gradle / Ivy

There is a newer version: 5.2.1
Show newest version
/*
Kontraktor Copyright (c) Ruediger Moeller, All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

See https://www.gnu.org/licenses/lgpl.txt
*/

package org.nustaq.kontraktor;

import org.nustaq.kontraktor.impl.BackOffStrategy;
import org.nustaq.kontraktor.impl.DispatcherThread;
import org.nustaq.kontraktor.monitoring.Monitorable;
import org.nustaq.kontraktor.remoting.base.ConnectionRegistry;
import org.nustaq.kontraktor.remoting.encoding.RemoteCallEntry;

import java.lang.reflect.InvocationHandler;
import java.util.Queue;
import java.util.concurrent.Callable;
import java.util.function.BiFunction;

/**
 * Scheduler manages scheduling of actors to threads. As kontraktor 3.0 simplyfies
 * scheduling compared to 2.0, this class currently doesn't do a lot.
 */
public interface Scheduler extends Monitorable{

    int getDefaultQSize();

    // yield during polling/spinlooping
    void pollDelay(int count);

    void put2QueuePolling(Queue q, boolean isCBQ, Object o, Object sender);

    Object enqueueCall(Actor sendingActor, Actor receiver, String methodName, Object args[], boolean isCB);

    Object enqueueCall(ConnectionRegistry reg, Actor sendingActor, Actor receiver, String methodName, Object[] args, boolean isCB);

    /**
     * Warning: side effects on RCE transient to pass Method object from lookup up the calling hierarchy
     *
     * @param reg
     * @param sendingActor
     * @param receiver
     * @param methodName
     * @param args
     * @param isCB
     * @param securityContext
     * @param callInterceptor
     * @param remoteCallEntry
     * @return
     */
    Object enqueueCallFromRemote(ConnectionRegistry reg, Actor sendingActor, Actor receiver, String methodName, Object[] args, boolean isCB, Object securityContext, BiFunction callInterceptor, RemoteCallEntry remoteCallEntry);

    void threadStopped(DispatcherThread th);

    void terminateIfIdle();

    InvocationHandler getInvoker(Actor dispatcher, Object toWrap);

    /**
     * Creates a wrapper on the given object enqueuing all calls to INTERFACE methods of the given object to the given actors's queue.
     * This is used to enable processing of resulting callback's in the callers thread.
     * see also @InThread annotation.
     * @param callback
     * @param 
     * @return
     */
     T inThread(Actor actor, T callback);

    void delayedCall(long millis, Runnable toRun);

     void runBlockingCall(Actor emitter, Callable toCall, Callback resultHandler);

    public DispatcherThread assignDispatcher(int minLoadPerc);

    /** called from inside overloaded thread with load
     * all actors assigned to the calling thread therefore can be safely moved
     * @param dispatcherThread
     */
    void rebalance(DispatcherThread dispatcherThread);

    BackOffStrategy getBackoffStrategy();

    void tryStopThread(DispatcherThread dispatcherThread);

    void tryIsolate(DispatcherThread dp, Actor actorRef);

    /**
     * @return number of actors scheduled by this scheduler. Note this
     * is not precise as not thread safe'd.
     */
    int getNumActors();

    /**
     * maps a JsonMapped result of a promise in case
     * @param result
     * @return
     */
    Object mapResult( Object result, RemoteCallEntry rce );


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy