List of usage examples for io.netty.util.concurrent Future isSuccess
boolean isSuccess();
From source file:connection.bootstrap.Authentication.java
@Override public void operationComplete(Future<Channel> future) throws Exception { System.out.println("Handshake success: " + future.isSuccess()); if (future.isSuccess()) { future.get().write(//from w w w . j a v a 2 s . c o m new ConsoleMessage("Welcome to PubliCaptivation" + " secure stream2Me service!", Server.name)); future.get().write(new ConsoleMessage("Your session is protectd by " + sslHandler.engine().getSession().getCipherSuite() + " cipher suite.", Server.name)); future.get().flush(); Handler.connections.add(future.get()); } else { try { future.get().close(); } catch (Exception e) { } } }
From source file:de.unipassau.isl.evs.ssh.app.handler.AbstractAppHandler.java
License:Open Source License
/** * Generate a new Future that will track the status of the request contained in the given sent AddressedMessage. * If the AddressedMessage couldn't be sent due to an IOException, the returned Future will also fail. * Otherwise, the returned Future will complete once {@link #handleResponse(Message.AddressedMessage)} with the * according response message is called. * <p/>//from w ww . j ava2s. c o m * <i>The generic return type of this method T must match the payload of the response message. * If you are e.g. expecting a {@link de.unipassau.isl.evs.ssh.core.messaging.RoutingKeys#MASTER_LIGHT_GET_REPLY} * response, the returned Future should be a Future<LightPayload>. If a error response with an {@link ErrorPayload} * is received, the Future will fail the cause being the received ErrorPayload. * If the request can have more than one successful response * (except for the ErrorPayload, which is always handled as described above and doesn't count here), * the most common supertype of both payloads (i.e. MessagePayload) must be declared as generic type for the Future.</i> */ protected <T> Future<T> newResponseFuture(final Message.AddressedMessage message) { if (!message.getFromID().equals(requireComponent(NamingManager.KEY).getOwnID())) { throw new IllegalArgumentException("Can only track messages sent by me"); } final Promise<T> promise = requireComponent(ExecutionServiceComponent.KEY).newPromise(); final MessageMetrics metrics; if (CoreConstants.TRACK_STATISTICS) { metrics = new MessageMetrics(message); promise.addListener(new FutureListener<T>() { @Override public void operationComplete(Future<T> future) throws Exception { metrics.finished(future); Log.v(AbstractAppHandler.this.getClass().getSimpleName() + "-Metrics", metrics.toString()); } }); } else { metrics = null; } message.getSendFuture().addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { if (!future.isSuccess()) { promise.setFailure(future.cause()); } else { if (metrics != null) { metrics.sent(future); } } } }); promise.setUncancellable(); mappings.put(message.getSequenceNr(), promise); return promise; }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppDoorHandler.java
License:Open Source License
/** * Sends a "OpenDoor" message to the master. *//*from w w w . ja v a 2 s.c o m*/ public void unlatchDoor() { final String door = getDoor(); if (door == null) { Log.e(TAG, "Could not open the door. No door buzzer installed"); fireUnlatchActionFinished(false); return; } DoorPayload doorPayload = new DoorPayload(door); final Message.AddressedMessage messageToMaster = sendMessageToMaster(MASTER_DOOR_UNLATCH, new Message(doorPayload)); final Future<Void> messagePayloadFuture = newResponseFuture(messageToMaster); messagePayloadFuture.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { fireUnlatchActionFinished(future.isSuccess()); } }); }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppDoorHandler.java
License:Open Source License
private void blockDoor(boolean isBlocked) { final String door = getDoor(); if (door == null) { Log.e(TAG, "Could not (un)block the door. No door sensor installed"); fireBlockActionFinished(false);/* ww w .j av a2 s .c o m*/ return; } DoorBlockPayload doorPayload = new DoorBlockPayload(isBlocked, door); final Future<DoorStatusPayload> future = newResponseFuture( sendMessageToMaster(MASTER_DOOR_BLOCK, new Message(doorPayload))); future.addListener(new FutureListener<DoorStatusPayload>() { @Override public void operationComplete(Future<DoorStatusPayload> future) throws Exception { boolean wasSuccessful = future.isSuccess(); if (wasSuccessful) { final DoorStatusPayload payload = future.get(); isDoorBlocked = payload.isBlocked(); isDoorOpen = payload.isOpen(); } fireBlockActionFinished(wasSuccessful); } }); }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppDoorHandler.java
License:Open Source License
/** * Refreshes the door photo by sending a message. *//*from w w w . ja va 2s .co m*/ public void refreshImage() { List<Module> cameras = requireComponent(AppModuleHandler.KEY).getCameras(); if (cameras.size() < 1) { Log.e(TAG, "Could not refresh the door image. No camera available"); fireCameraActionFinished(false); return; } CameraPayload payload = new CameraPayload(0, cameras.get(0).getName()); final Future<CameraPayload> future = newResponseFuture( sendMessageToMaster(MASTER_CAMERA_GET, new Message(payload))); future.addListener(new FutureListener<CameraPayload>() { @Override public void operationComplete(Future<CameraPayload> future) throws Exception { final boolean success = future.isSuccess(); if (success) { picture = future.get().getPicture(); } fireCameraActionFinished(success); } }); }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppDoorHandler.java
License:Open Source License
/** * Requests the door status from master by sending him a message. *//*from w w w .ja va 2 s . co m*/ public void requestDoorStatus() { Message message = new Message(new DoorPayload(getDoor())); final Future<DoorStatusPayload> future = newResponseFuture(sendMessageToMaster(MASTER_DOOR_GET, message)); future.addListener(new FutureListener<DoorStatusPayload>() { @Override public void operationComplete(Future<DoorStatusPayload> future) throws Exception { if (future.isSuccess()) { handleUpdate(future.get()); } } }); }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppHolidaySimulationHandler.java
License:Open Source License
/** * Changes the statue of the Holiday Simulation. When parameter on is {@code true} the simulation will start. * Otherwise the Simulation will stop./*from w ww . ja va2 s .c o m*/ * * @param on {@code true} to start the holiday simulation, {@code false} to stop the holiday simulation. */ public void switchHolidaySimulation(boolean on) { final HolidaySimulationPayload payload = new HolidaySimulationPayload(on); final Message.AddressedMessage message = sendMessageToMaster(MASTER_HOLIDAY_SET, new Message(payload)); final Future<HolidaySimulationPayload> future = newResponseFuture(message); future.addListener(new FutureListener<HolidaySimulationPayload>() { @Override public void operationComplete(Future<HolidaySimulationPayload> future) throws Exception { boolean isSuccess = future.isSuccess(); if (isSuccess) { isOn = future.get().switchOn(); } fireHolidayModeSet(isSuccess); } }); }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppLightHandler.java
License:Open Source License
/** * Sends a GET-request for the status of a module. *///from w ww .j a v a 2 s .c o m private void requestLightStatus(Module m) { LightPayload lightPayload = new LightPayload(false, m); Message message = new Message(lightPayload); final Future<LightPayload> future = newResponseFuture(sendMessageToMaster(MASTER_LIGHT_GET, message)); future.addListener(new FutureListener<LightPayload>() { @Override public void operationComplete(Future<LightPayload> future) throws Exception { boolean wasSuccess = future.isSuccess(); if (wasSuccess) { LightPayload payload = future.get(); setCachedStatus(payload.getModule(), payload.getOn()); } fireLightGetFinished(wasSuccess); } }); }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppLightHandler.java
License:Open Source License
/** * Sends a SET-request with the light-module and its status. * * @param module The light-module which status should be changed. * @param status The status of the module. *//*w ww .j av a 2 s .c om*/ private void setLight(Module module, boolean status) { LightPayload lightPayload = new LightPayload(status, module); Message message = new Message(lightPayload); final Future<LightPayload> future = newResponseFuture(sendMessageToMaster(MASTER_LIGHT_SET, message)); future.addListener(new FutureListener<LightPayload>() { @Override public void operationComplete(Future<LightPayload> future) throws Exception { boolean wasSuccess = future.isSuccess(); if (wasSuccess) { LightPayload payload = future.get(); setCachedStatus(payload.getModule(), payload.getOn()); } fireLightSetFinished(wasSuccess); } }); }
From source file:de.unipassau.isl.evs.ssh.app.handler.AppModifyModuleHandler.java
License:Open Source License
/** * Registers the given module. Invoker of this method can be notified with a NewModuleListener * when the registration is finished./*from ww w. ja va 2s.co m*/ * * @param module the module to register */ public void addNewModule(Module module) { ModifyModulePayload payload = new ModifyModulePayload(module); final Future<Void> future = newResponseFuture(sendMessageToMaster(MASTER_MODULE_ADD, new Message(payload))); future.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { fireRegistrationFinished(future.isSuccess()); } }); }