Search in sources :

Example 1 with Scheduler

use of com.swiftmq.impl.routing.single.schedule.Scheduler in project swiftmq-ce by iitsoftware.

the class RoutingSwiftletImpl method createStaticRoutes.

private void createStaticRoutes(EntityList staticRouteList) throws SwiftletException {
    String[] staticRoutes = staticRouteList.getEntityNames();
    if (staticRoutes != null) {
        for (int i = 0; i < staticRoutes.length; i++) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "creating static route to: " + staticRoutes[i]);
            try {
                Scheduler scheduler = ctx.schedulerRegistry.getScheduler(staticRoutes[i]);
                addRoute(new RouteImpl(staticRoutes[i], scheduler.getQueueName(), true, scheduler));
            } catch (Exception e) {
                throw new SwiftletException(e.getMessage());
            }
        }
    }
    staticRouteList.setEntityAddListener(new EntityChangeAdapter(null) {

        public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
            String dest = newEntity.getName();
            try {
                SwiftUtilities.verifyRouterName(dest);
                Scheduler scheduler = ctx.schedulerRegistry.getScheduler(dest);
                RouteImpl route = (RouteImpl) getRoute(dest);
                if (route == null)
                    addRoute(new RouteImpl(dest, scheduler.getQueueName(), false, scheduler));
                else {
                    route.setStaticRoute(true);
                    if (route.getScheduler() == null)
                        route.setScheduler(scheduler);
                }
            } catch (Exception e) {
                throw new EntityAddException(e.getMessage());
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityAdd (staticroute.routers): new staticroute=" + dest);
        }
    });
    staticRouteList.setEntityRemoveListener(new EntityChangeAdapter(null) {

        public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
            String dest = delEntity.getName();
            try {
                Scheduler scheduler = ctx.schedulerRegistry.getScheduler(dest);
                if (scheduler.getNumberConnections() == 0) {
                    scheduler.close();
                    removeRoute(getRoute(dest));
                }
            } catch (Exception e) {
                throw new EntityRemoveException(e.getMessage());
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove (staticroute.routers): del staticroute=" + dest);
        }
    });
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) Scheduler(com.swiftmq.impl.routing.single.schedule.Scheduler) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 2 with Scheduler

use of com.swiftmq.impl.routing.single.schedule.Scheduler in project swiftmq-ce by iitsoftware.

the class RouteExchanger method visit.

public void visit(PORouteObject po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/visit, po=" + po + " ...");
    Route route = po.getRoute();
    try {
        Scheduler scheduler = ctx.schedulerRegistry.getScheduler(route.getDestinationRouter());
        if (route.getType() == Route.ADD) {
            routeTable.addRoute(route);
            scheduler.addRoute(route);
        } else {
            routeTable.removeRoute(route);
            scheduler.removeRoute(route);
        }
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/visit, po=" + po + ", exception scheduling: " + e);
    }
    List connections = routeTable.getRoutingConnections();
    if (connections != null) {
        for (int i = 0; i < connections.size(); i++) {
            RoutingConnection rc = (RoutingConnection) connections.get(i);
            sendRoute(rc, route);
        }
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/visit, po=" + po + " done");
}
Also used : Scheduler(com.swiftmq.impl.routing.single.schedule.Scheduler) RoutingConnection(com.swiftmq.impl.routing.single.connection.RoutingConnection) List(java.util.List)

Example 3 with Scheduler

use of com.swiftmq.impl.routing.single.schedule.Scheduler in project swiftmq-ce by iitsoftware.

the class RouteExchanger method visit.

public void visit(POConnectionRemoveObject po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/visit, po=" + po + " ...");
    ctx.schedulerRegistry.removeRoutingConnection(po.getRoutingConnection());
    List routes = routeTable.removeConnectionRoutes(po.getRoutingConnection());
    if (routes != null) {
        for (int i = 0; i < routes.size(); i++) {
            Route route = (Route) routes.get(i);
            try {
                Scheduler scheduler = ctx.schedulerRegistry.getScheduler(route.getDestinationRouter());
                scheduler.removeRoute(route);
                if (scheduler.getNumberConnections() == 0)
                    ctx.schedulerRegistry.removeScheduler(route.getDestinationRouter());
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/visit, po=" + po + ", exception while removing route from scheduler: " + e);
            }
            List connections = routeTable.getRoutingConnections();
            if (connections != null) {
                for (int j = 0; j < connections.size(); j++) {
                    RoutingConnection rc = (RoutingConnection) connections.get(j);
                    sendRoute(rc, route);
                }
            }
        }
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/visit, po=" + po + " done");
}
Also used : Scheduler(com.swiftmq.impl.routing.single.schedule.Scheduler) RoutingConnection(com.swiftmq.impl.routing.single.connection.RoutingConnection) List(java.util.List)

Aggregations

Scheduler (com.swiftmq.impl.routing.single.schedule.Scheduler)3 RoutingConnection (com.swiftmq.impl.routing.single.connection.RoutingConnection)2 List (java.util.List)2 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1