@Override public Entity getEntity(String id) { return super.getEntity(id); }
@Override protected void disconnectFromBasys() { ch.close(); super.disconnectFromBasys(); }
@Override public void activate(ComponentContext context) throws ComponentException { super.activate(context); executor.scheduleWithFixedDelay(new Runnable() {
@Override public void disconnectFromExternal() { super.disconnectFromExternal(); try { outgoing.forEach((channel, mp) -> { channel.close(); }); incoming.forEach((mc, channel) -> { channel.close(); }); mqttClient.disconnect().waitForCompletion(); } catch (MqttException e) { LOGGER.warn("MqttGatewayComponent \"" + getId() + "\"" + " cannot disconnect", e); } }
@Override public void connectToExternal() throws ComponentException { super.connectToExternal(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(getConfig().getExternalConnectionString()); try { connection = connectionFactory.createConnection(); connection.setClientID(getId()); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } catch (JMSException e) { throw new ComponentException(e); } for (Property p : getConfig().getProperties()) { if (p.getKey().equals("incoming")) { String[] parts = p.getValue().split(" "); installOutgoingChannel(parts[0], parts[1]); } if (p.getKey().equals("outgoing")) { String[] parts = p.getValue().split(" "); installIncomingChannel(parts[0], parts[1]); } } }
@Override public void deactivate() throws ComponentException { super.deactivate(); try { System.out.println("attempt to shutdown executor"); executor.shutdown(); executor.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { System.err.println("tasks interrupted"); } finally { if (!executor.isTerminated()) { System.err.println("cancel non-finished tasks"); } List<Runnable> runnables = executor.shutdownNow(); System.out.println("shutdown finished"); } }
@Override protected void connectToBasys() { super.connectToBasys(); ch = CommFactory.getInstance().openChannel(context.getSharedChannelPool(), "worldmodel-manager#out", false, new ChannelListener() { @Override public de.dfki.cos.basys.platform.model.runtime.communication.Response handleRequest(Channel channel, Request req) { return null; } @Override public void handleNotification(Channel channel, Notification not) { try { EObject payload = JsonUtils.fromString(not.getPayload(), EObject.class); if (payload.eClass() .equals(LinebalancingPackage.eINSTANCE.getLineBalancingAssignment())) { assignedResource = (LineBalancingAssignment) payload; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void handleMessage(Channel channel, String msg) { } } ); }
@Override public void activate(ComponentContext context) throws ComponentException { super.activate(context);
@Override public void disconnectFromExternal() { super.disconnectFromExternal();
@Override public void connectToExternal() throws ComponentException { super.connectToExternal();