org.wildfly.swarm.topology.TopologyListener Java Examples

The following examples show how to use org.wildfly.swarm.topology.TopologyListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.as(TopologyArchive.class).advertise("restaurantService");
    deployment.setContextRoot("/api");
    deployment.addPackages(true, "org.jboss.shrinkwrap.api");
    deployment.addAsLibrary(container.createDefaultDeployment());
    deployment.addAllDependencies();
    container.start();
    container.deploy(deployment);

    Topology lookup = Topology.lookup();
    lookup.addListener(new TopologyListener() {
        @Override
        public void onChange(Topology tplg) {
            System.out.println(">>> Delivery Service: The Topology Has Changed!");
            printTopology(lookup);
        }
    });
    
    printTopology(lookup);

}
 
Example #2
Source File: App.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.as(TopologyArchive.class).advertise("deliveryService");
    deployment.setContextRoot("/api");
    deployment.addPackages(true, "org.jboss.shrinkwrap.api");
    deployment.addAsLibrary(container.createDefaultDeployment());
    deployment.addAllDependencies();
    container.start();
    container.deploy(deployment);
    
    Topology lookup = Topology.lookup();
    lookup.addListener(new TopologyListener() {
        @Override
        public void onChange(Topology tplg) {
            System.out.println(">>> Delivery Service: The Topology Has Changed!");
            printTopology(lookup);
        }
    });
    
    printTopology(lookup);
    
}
 
Example #3
Source File: App.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.as(TopologyArchive.class).advertise("foodService");
    deployment.setContextRoot("/api");
    deployment.addPackages(true, "org.jboss.shrinkwrap.api");
    deployment.addAsLibrary(container.createDefaultDeployment());
    deployment.addAllDependencies();
    container.start();
    container.deploy(deployment);
    
    Topology lookup = Topology.lookup();
    lookup.addListener(new TopologyListener() {
        @Override
        public void onChange(Topology tplg) {
            System.out.println(">>> Delivery Service: The Topology Has Changed!");
            printTopology(lookup);
        }
    });
    
    printTopology(lookup);
    
}
 
Example #4
Source File: TopologySSEServlet.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.setContentType("text/event-stream");
    resp.setCharacterEncoding("UTF-8");

    AsyncContext asyncContext = req.startAsync();
    PrintWriter writer = resp.getWriter();

    TopologyListener topologyListener = new SSETopologyListener(writer, req.isSecure());

    ScheduledFuture keepAlive = this.keepAliveExecutor.scheduleAtFixedRate(
            new KeepAliveRunnable(writer, topologyListener),
            10,
            15,
            TimeUnit.SECONDS);
    asyncContext.setTimeout(0);
    asyncContext.addListener(new TopologyAsyncListener(topology, topologyListener, keepAlive));


    this.topology.addListener(topologyListener);
    String json = topologyToJson(req.isSecure());
    writer.write("event: topologyChange\n");
    writer.write("data: " + json);
    writer.flush();

}
 
Example #5
Source File: TopologyManager.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private void fireListeners() {
    List<TopologyListener> currentListeners = new ArrayList<>();
    currentListeners.addAll(this.listeners);
    currentListeners.forEach((e) -> {
        executor.execute(() -> {
            try {
                e.onChange(this);
            } catch (Throwable t) {
                TopologyMessages.MESSAGES.errorFiringEvent(e.getClass().getName(), t);
                removeListener(e);
            }
        });
    });
}
 
Example #6
Source File: TopologyManager.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
private void fireListeners() {
    List<TopologyListener> currentListeners = new ArrayList<>();
    currentListeners.addAll(this.listeners);
    currentListeners.forEach((e) -> {
        executor.execute(() -> {
            try {
                e.onChange(this);
            } catch (Throwable t) {
                removeListener(e);
            }
        });
    });
}
 
Example #7
Source File: TopologySSEServlet.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public KeepAliveRunnable(PrintWriter writer, TopologyListener topologyListener) {
    this.writer = writer;
    this.topologyListener = topologyListener;
}
 
Example #8
Source File: TopologySSEServlet.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public TopologyAsyncListener(Topology topology, TopologyListener topologyListener, ScheduledFuture scheduledFuture) {
    this.topology = topology;
    this.topologyListener = topologyListener;
    this.keepAlive = scheduledFuture;
}
 
Example #9
Source File: TopologyManager.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public synchronized void addListener(TopologyListener listener) {
    this.listeners.add(listener);
}
 
Example #10
Source File: TopologyManager.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public synchronized void removeListener(TopologyListener listener) {
    this.listeners.remove(listener);
}
 
Example #11
Source File: TopologyManager.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public synchronized void addListener(TopologyListener listener) {
    this.listeners.add(listener);
}
 
Example #12
Source File: TopologyManager.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public synchronized void removeListener(TopologyListener listener) {
    this.listeners.remove(listener);
}