public void perform(Consumer<T> action) { if (processed.isEmpty()) { space.process(() -> { onSuccess.accept(null); }); } else { processed.stream().forEach(action); } } }
public static void run(String aModuleName) { Scripts.getSpace().process(() -> { try { ScriptedResource._require(new String[]{aModuleName}, null, Scripts.getSpace(), new HashSet<>(), (Void v) -> { Logger.getLogger(PlatypusClientApplication.class.getName()).log(Level.INFO, "Platypus application started."); }, (Exception ex) -> { Logger.getLogger(PlatypusClientApplication.class.getName()).log(Level.SEVERE, null, ex); }); } catch (Exception ex) { Logger.getLogger(PlatypusClientApplication.class.getName()).log(Level.SEVERE, null, ex); } }); }
@ScriptFunction(params = {"uri"}) public WebSocketClientSession(String aUri) throws Exception { super(); Scripts.getSpace().process(() -> { try { webSocketSession = ContainerProvider.getWebSocketContainer().connectToServer(endPoint, URI.create(aUri)); } catch (DeploymentException | IOException ex) { Logger.getLogger(WebSocketClientSession.class.getName()).log(Level.SEVERE, null, ex); } }); }
public JSObject executeQuery(Consumer<JSObject> onSuccess, Consumer<Exception> onFailure, Scripts.Space aSpace) throws Exception { if (basesProxy != null) { PlatypusJdbcFlowProvider flow = basesProxy.createFlowProvider(datasourceName, entityName, sqlClause, expectedFields); flow.setPageSize(pageSize); flow.setProcedure(procedure); Collection<Map<String, Object>> data = flow.refresh(parameters, onSuccess != null ? (Collection<Map<String, Object>> aData) -> { aSpace.process(() -> { JSObject aJsData = aSpace.readJsArray(aData); onSuccess.accept(aJsData); }); } : null, onFailure != null ? (Exception ex) -> { aSpace.process(() -> { onFailure.accept(ex); }); } : null); return data != null ? aSpace.readJsArray(data) : null; } else { return null; } }
public void schedule(JSObject aJsTask, long aTimeout) { Scripts.LocalContext context = Scripts.getContext(); bio.submit(() -> { try { Thread.sleep(aTimeout); Scripts.setContext(context); try { process(() -> { aJsTask.call(null, new Object[]{}); }); } finally { Scripts.setContext(null); } } catch (InterruptedException ex) { Logger.getLogger(Scripts.class.getName()).log(Level.SEVERE, null, ex); } }); }
@Override public Object received(Packet aPacket) throws Exception { Session session = serverCore.getSessionManager().getSystemSession(); Scripts.LocalContext context = new Scripts.LocalContext(session.getPrincipal(), session); session.getSpace().process(context, () -> { serverCore.executeMethod(moduleName, RECIEVER_METHOD_NAME, new Object[]{aPacket}, true, (Object result) -> { if (result != null) { assert result instanceof String; assert sender != null; sender.send(aPacket, (String) result); } }, (Exception ex) -> { Logger.getLogger(PositioningPacketReciever.class.getName()).log(Level.WARNING, null, ex); }); }); return null; } }
protected void internalExecute(final Consumer<JSObject> aOnSuccess, final Consumer<Exception> aOnFailure) throws Exception { if (query == null) { throw new IllegalStateException("Query must present. Query name: " + queryName + "; tableName: " + getTableNameForDescription()); } bindQueryParameters(); if (isValid()) { if (aOnSuccess != null) { Scripts.getSpace().process(() -> { aOnSuccess.accept(null); }); } } else { // Requery if query parameters values have been changed while bindQueryParameters() call // or we are forced to refresh the data via requery() call. silentUnpend(); JSObject jsRowset = refreshRowset(aOnSuccess, aOnFailure); assert pending != null || (aOnSuccess == null && model.process == null); } }
/** * For external API. * * @param aWrapped * @return BiConsumer<Object, Throwable> Object - result instance, * Throwable - exception raised while an operation. */ public static BiConsumer<Object, Throwable> inContext(BiConsumer<Object, Throwable> aWrapped) { Space callingSpace = getSpace(); LocalContext callingContext = getContext(); return (Object aResult, Throwable aReason) -> { callingSpace.process(callingContext, () -> { aWrapped.accept(aResult, aReason); }); }; }
@Override public void logout(JSObject aOnSuccess, JSObject aOnFailure) throws Exception { servletRequest.logout(); servletRequest.getSession().invalidate(); if (aOnSuccess != null) { // async style Scripts.getSpace().process(() -> { aOnSuccess.call(null, new Object[]{}); }); } else { // sync style } } }
public void process(Runnable aTask) { Scripts.LocalContext context = Scripts.getContext(); process(context, aTask); }
@OnError public void onError(Session websocketSession, Throwable aError) { if (onerror != null) { space.process(context, () -> { JSObject errorEvent = Scripts.getSpace().makeObj(); errorEvent.setMember("message", aError.getMessage()); onerror.call(session.getPublished(), new Object[]{errorEvent}); }); } }
@OnMessage public void onMessage(Session websocketSession, String aData) { if (onmessage != null) { space.process(context, () -> { JSObject messageEvent = Scripts.getSpace().makeObj(); messageEvent.setMember("data", aData); onmessage.call(session.getPublished(), new Object[]{messageEvent}); }); } }
@Override public void failed(Throwable exc, Object attachment) { callingSpace.process(callingContext, () -> { if (aOnFailure != null) { aOnFailure.call(null, new Object[]{exc.toString()}); } }); } };
public void enqueue(JSObject aJsTask) { process(() -> { aJsTask.call(null, new Object[]{}); }); }
@OnClose public void onClose(Session websocketSession, CloseReason aReason) { if (onclose != null) { space.process(context, () -> { JSObject closeEvent = Scripts.getSpace().makeObj(); closeEvent.setMember("wasClean", aReason.getCloseCode() == CloseReason.CloseCodes.NORMAL_CLOSURE); closeEvent.setMember("code", aReason.getCloseCode().getCode()); closeEvent.setMember("reason", aReason.getReasonPhrase()); onclose.call(session.getPublished(), new Object[]{closeEvent}); }); } }
@Override public void logout(JSObject aOnSuccess, JSObject aOnFailure) throws Exception { if (aOnSuccess != null) { // async style Scripts.getSpace().process(() -> { aOnSuccess.call(null, new Object[]{}); }); } else { // sync style } } }
@Override public void logout(JSObject aOnSuccess, JSObject aOnFailure) throws Exception { if (aOnSuccess != null) { // async style Scripts.getSpace().process(() -> { aOnSuccess.call(null, new Object[]{}); }); } // sync style } }
@Override public void logout(JSObject aOnSuccess, JSObject aOnFailure) throws Exception { if (aOnSuccess != null) { // async style Scripts.getSpace().process(() -> { aOnSuccess.call(null, new Object[]{}); }); } // sync style } }
@OnOpen public void onOpen(Session aSession) { if (onopen != null) { space.process(context, () -> { onopen.call(session.getPublished(), new Object[]{}); }); } }
@Override public void completed(Integer result, Object attachment) { callingSpace.process(callingContext, () -> { if (aOnSuccess != null) { aOnSuccess.call(null, new Object[]{result}); } }); }