@Override public void execute(Runnable command) { actor.execute(command); } }
@Override public void execute(Runnable command) { actor.execute(command); } }
public void inFacadeThread(Runnable toRun) { if (facadeActor!=null) { if ( Thread.currentThread() != facadeActor.getCurrentDispatcher() ) { facadeActor.execute( toRun ); return; } } else { int debug = 1; } toRun.run(); }
public void inFacadeThread(Runnable toRun) { if (facadeActor!=null) { if ( Thread.currentThread() != facadeActor.getCurrentDispatcher() ) { facadeActor.execute( toRun ); return; } } else { int debug = 1; } toRun.run(); }
public IPromise connect(String host, int port, BiFunction<SelectionKey,SocketChannel,AsyncSocketConnection> connectionFactory) { if ( connectFuture != null ) { throw new RuntimeException("illegal state, connect is underway"); } connectFuture = new Promise<>(); this.connectionFactory = connectionFactory; try { channel = SocketChannel.open(); channel.configureBlocking(false); selector = Selector.open(); channel.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE ); channel.connect(new InetSocketAddress(host, port)); Actor.current().execute(this); } catch (Exception e) { connectFuture.reject(e); connectFuture = null; } return connectFuture; }
public IPromise connect(String host, int port, BiFunction<SelectionKey,SocketChannel,AsyncSocketConnection> connectionFactory) { if ( connectFuture != null ) { throw new RuntimeException("illegal state, connect is underway"); } connectFuture = new Promise<>(); this.connectionFactory = connectionFactory; try { channel = SocketChannel.open(); channel.configureBlocking(false); selector = Selector.open(); channel.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE ); channel.connect(new InetSocketAddress(host, port)); Actor.current().execute(this); } catch (Exception e) { connectFuture.reject(e); connectFuture = null; } return connectFuture; }
protected HttpObjectSocket restoreSessionFromId(String sessionId) { if ( facade instanceof SessionResurrector) { HttpObjectSocket sock = new HttpObjectSocket( sessionId, () -> facade.execute( () -> closeSession(sessionId))) { @Override protected int getObjectMaxBatchSize() { return HttpObjectSocket.HTTP_BATCH_SIZE; } @Override public String getConnectionIdentifier() { return sessionId; } }; sessions.put( sock.getSessionId(), sock ); ObjectSink sink = factory.apply(sock); sock.setSink(sink); return sock; } return null; }
/** * return a future which is completed upon connection close * * @param reg * * @return future completed upon termination of scheduling (disconnect) * */ public IPromise scheduleSendLoop(ConnectionRegistry reg) { Promise promise = new Promise(); sendJobs.add(new ScheduleEntry(reg, promise)); synchronized (this) { if ( ! loopStarted ) { loopStarted = true; Actor.current().execute(this); } } return promise; }
/** * return a future which is completed upon connection close * * @param reg * * @return future completed upon termination of scheduling (disconnect) * */ public IPromise scheduleSendLoop(ConnectionRegistry reg) { Promise promise = new Promise(); sendJobs.add(new ScheduleEntry(reg, promise)); synchronized (this) { if ( ! loopStarted ) { loopStarted = true; Actor.current().execute(this); } } return promise; }
@Override public void onResult(SendResult result) { if ( ! result.isOK() ) { executor.execute( () -> { FSTUtil.<RuntimeException>rethrow(result.getException()); try { close(); } catch (IOException e) { Log.Warn(this,e); } }); } } });
HttpObjectSocket sock = new HttpObjectSocket( sessionId, () -> facade.execute( () -> closeSession(finalSessionId))) { @Override protected int getObjectMaxBatchSize() {
@Override public void onDataAvailable() throws IOException { if ( buffer == null ) { int available = aCtx.getRequest().getContentLength(); buffer = new byte[available]; } int c; while( inputStream.isReady() && (c=inputStream.read()) != -1 ) { buffer[index++] = (byte) c; } if ( index == buffer.length ) { facade.execute( () -> { connector.requestReceived(getApiPath(),aCtx,buffer); }); } }
public static Promise<ActorServer> Publish(Actor facade, int port, Coding coding, Consumer<Actor> disconnectCB) { Promise finished = new Promise(); try { ActorServer publisher = new ActorServer(new TCPServerConnector(port), facade, coding); facade.execute(() -> { try { publisher.start(disconnectCB); finished.resolve(publisher); } catch (Exception e) { finished.reject(e); } }); } catch (Exception e) { e.printStackTrace(); return new Promise(null,e); } return finished; }
public static Promise<ActorServer> Publish(Actor facade, int port, Coding coding, Consumer<Actor> disconnectCB) { Promise finished = new Promise(); try { ActorServer publisher = new ActorServer(new TCPServerConnector(port), facade, coding); facade.execute(() -> { try { publisher.start(disconnectCB); finished.resolve(publisher); } catch (Exception e) { finished.reject(e); } }); } catch (Exception e) { e.printStackTrace(); return new Promise(null,e); } return finished; }
public static Promise<ActorServer> Publish(Actor facade, int port, Coding coding, Consumer<Actor> disconnectHandler) { Promise finished = new Promise(); try { ActorServer publisher = new ActorServer(new NIOServerConnector(port), facade, coding); facade.execute(() -> { try { publisher.start(disconnectHandler); finished.resolve(publisher); } catch (Exception e) { finished.reject(e); } }); } catch (Exception e) { e.printStackTrace(); return new Promise(null,e); } return finished; }
public static Promise<ActorServer> Publish(Actor facade, int port, Coding coding, Consumer<Actor> disconnectHandler) { Promise finished = new Promise(); try { ActorServer publisher = new ActorServer(new NIOServerConnector(port), facade, coding); facade.execute(() -> { try { publisher.start(disconnectHandler); finished.resolve(publisher); } catch (Exception e) { finished.reject(e); } }); } catch (Exception e) { e.printStackTrace(); return new Promise(null,e); } return finished; }
@Override public IPromise<ActorServer> publish(Consumer<Actor> disconnectCallback) { Promise finished = new Promise(); try { ActorServer publisher = new ActorServer( new UndertowWebsocketServerConnector(urlPath,port,hostName).sendStrings(sendStringMessages).sendSid(sendSid), facade, coding ); facade.execute(() -> { try { publisher.start(disconnectCallback); finished.resolve(publisher); } catch (Exception e) { finished.reject(e); } }); } catch (Exception e) { e.printStackTrace(); return new Promise(null,e); } return finished; }
connectable.actorClass(Krouter.class); service.execute( () -> { connectable .connect(null, (Consumer<Actor>) disconnectCallback)
connectable.actorClass(Krouter.class); service.execute( () -> { connectable .connect(null, (Consumer<Actor>) disconnectCallback)