blob: 471419fe17b6248413feb48afa1ff98a069901b2 [file] [log] [blame]
package org.eclipse.osbp.runtime.common.session;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
import java.util.function.Predicate;
import org.eclipse.osbp.runtime.common.session.ISessionManager.FutureResult;
/**
* And abstraction above a state. Eg. Vaadin UI.
*/
public interface ISession {
String HOSTNAME = "hostname";
String IS_SLAVE = "slave";
/**
* Returns the host address of the session.
*
* @return
*/
String getHost();
/**
* Executes the function in the scope of the session.
*
* @param function
* @return
*/
<T> T apply(Function<ISession, T> function);
/**
* Creates a {@link CompletableFuture} for the given function. This method
* must NOT block.
*
* @param function
* @param callback
* @return
*/
<T> CompletableFuture<FutureResult<T>> async(final Function<ISession, T> function, SessionCallback<T> callback);
/**
* Creates a {@link CompletableFuture} for the given function. This method
* must NOT block.
*
* @param function
* @param callback
* @return
*/
<T> CompletableFuture<FutureResult<T>> async(final Function<ISession, T> function, SessionCallback<T> callback,
ExecutorService executor);
/**
* Sends the given data to the session. Call must by synced.
*
* @param data
*/
void sendData(Map<String, Object> data);
/**
* Returns the property associated with the key.
*
* @param key
* @return
*/
<T> T get(Class<T> key);
/**
* Returns the property associated with the key.
*
* @param key
* @return
*/
Object get(String key);
void set(String key, Object object);
/**
* Returns true, if the session has slave sessions. Otherwise false.
*
* @return
*/
boolean isMasterSession();
/**
* Returns true, if the session is a slave session and has a master session.
* Otherwise false.
*
* @return
*/
boolean isSlaveSession();
/**
* Returns the type {@link Type} of this session.
*
* @return
*/
Type getType();
/**
* Returns the master session, if the session is a slave session.
* <code>Null</code> otherwise.
*
* @return
*/
ISession getMaster();
/**
* Returns an unmodifiable list of all slave sessions connected to this
* master. Returns never <code>null</code>.
*
* @return
*/
List<ISession> getSlaves();
/**
* Returns a list of slaves filtered by given filter.
* @param filter
* @return
*/
List<ISession> getSlaves(Predicate<ISession> filter);
/**
* Adds a session which is a slave. Slaves are used to "paint" on web UIs
* controlled by the master session.
*
* @param name
* @return
*/
void addSlave(ISession slave);
/**
* See {@link #addSlaveSession(ISession)}
*
* @param slave
*/
void removeSlave(ISession slave);
/**
* In case of slave session, the session MUST provide a fragment following
* the pattern: {master-host}{UI-to-display}
*
* @return
*/
String getFragment();
enum Type {
MASTER, SLAVE;
}
}