Search in sources :

Example 96 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class BeanIODataFormatComplexTest method createTestData.

private List<Object> createTestData(boolean skipB1header) throws ParseException {
    String source = "camel-beanio";
    List<Object> body = new ArrayList<Object>();
    Date date = new SimpleDateFormat("ddMMyy").parse("030808");
    Header hFirst = new Header("A1", date, "PRICE");
    Header hSecond = new Header("B1", date, "SECURITY");
    Separator headerEnd = new Separator("HEADER END");
    A1Record first = new A1Record("0001917", source, 12345.678900);
    A1Record second = new A1Record("0002374", source, 59303290.020);
    B1Record third = new B1Record("0015219", source, "SECURITY ONE");
    Separator sectionEnd = new Separator("END OF SECTION 1");
    A1Record fourth = new A1Record("0076647", source, 0.0000000001);
    A1Record fifth = new A1Record("0135515", source, 999999999999d);
    B1Record sixth = new B1Record("2000815", source, "SECURITY TWO");
    B1Record seventh = new B1Record("2207122", source, "SECURITY THR");
    body.add(hFirst);
    if (!skipB1header) {
        body.add(hSecond);
    }
    body.add(headerEnd);
    body.add(first);
    body.add(second);
    body.add(third);
    body.add(sectionEnd);
    body.add(fourth);
    body.add(fifth);
    body.add(sixth);
    body.add(seventh);
    Trailer trailer = new Trailer(7);
    body.add(trailer);
    return body;
}
Also used : ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 97 with ArrayList

use of java.util.ArrayList in project antlrworks by antlr.

the class XJApplication method performQuit.

public void performQuit() {
    delegate.appWillTerminate();
    for (XJWindow window : new ArrayList<XJWindow>(windows)) {
        if (!window.performClose(false)) {
            // cancel quit if any document cannot or don't want to be closed
            return;
        }
    }
    XJFrame.closeDesktop();
    shutdown();
}
Also used : XJWindow(org.antlr.xjlib.appkit.frame.XJWindow) ArrayList(java.util.ArrayList)

Example 98 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DefaultCamelContext method shutdownRoute.

public synchronized void shutdownRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception {
    RouteService routeService = routeServices.get(routeId);
    if (routeService != null) {
        List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1);
        RouteStartupOrder order = new DefaultRouteStartupOrder(1, routeService.getRoutes().iterator().next(), routeService);
        routes.add(order);
        getShutdownStrategy().shutdown(this, routes, timeout, timeUnit);
        // must stop route service as well (and remove the routes from management)
        stopRouteService(routeService, true);
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder)

Example 99 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DefaultCamelContext method doSuspend.

@Override
protected void doSuspend() throws Exception {
    EventHelper.notifyCamelContextSuspending(this);
    log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is suspending");
    StopWatch watch = new StopWatch();
    // (so when we resume we only resume the routes which actually was suspended)
    for (Map.Entry<String, RouteService> entry : getRouteServices().entrySet()) {
        if (entry.getValue().getStatus().isStarted()) {
            suspendedRouteServices.put(entry.getKey(), entry.getValue());
        }
    }
    // assemble list of startup ordering so routes can be shutdown accordingly
    List<RouteStartupOrder> orders = new ArrayList<RouteStartupOrder>();
    for (Map.Entry<String, RouteService> entry : suspendedRouteServices.entrySet()) {
        Route route = entry.getValue().getRoutes().iterator().next();
        Integer order = entry.getValue().getRouteDefinition().getStartupOrder();
        if (order == null) {
            order = defaultRouteStartupOrder++;
        }
        orders.add(new DefaultRouteStartupOrder(order, route, entry.getValue()));
    }
    // suspend routes using the shutdown strategy so it can shutdown in correct order
    // routes which doesn't support suspension will be stopped instead
    getShutdownStrategy().suspend(this, orders);
    // mark the route services as suspended or stopped
    for (RouteService service : suspendedRouteServices.values()) {
        if (routeSupportsSuspension(service.getId())) {
            service.suspend();
        } else {
            service.stop();
        }
    }
    watch.stop();
    if (log.isInfoEnabled()) {
        log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is suspended in " + TimeUtils.printDuration(watch.taken()));
    }
    EventHelper.notifyCamelContextSuspended(this);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ShutdownRoute(org.apache.camel.ShutdownRoute) Route(org.apache.camel.Route) StopWatch(org.apache.camel.util.StopWatch)

Example 100 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DefaultCamelContext method createRouteStaticEndpointJson.

public String createRouteStaticEndpointJson(String routeId, boolean includeDynamic) {
    List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
    if (routeId != null) {
        RouteDefinition route = getRouteDefinition(routeId);
        if (route == null) {
            throw new IllegalArgumentException("Route with id " + routeId + " does not exist");
        }
        routes.add(route);
    } else {
        routes.addAll(getRouteDefinitions());
    }
    StringBuilder buffer = new StringBuilder("{\n  \"routes\": {");
    boolean firstRoute = true;
    for (RouteDefinition route : routes) {
        if (!firstRoute) {
            buffer.append("\n    },");
        } else {
            firstRoute = false;
        }
        String id = route.getId();
        buffer.append("\n    \"").append(id).append("\": {");
        buffer.append("\n      \"inputs\": [");
        // for inputs we do not need to check dynamic as we have the data from the route definition
        Set<String> inputs = RouteDefinitionHelper.gatherAllStaticEndpointUris(this, route, true, false);
        boolean first = true;
        for (String input : inputs) {
            if (!first) {
                buffer.append(",");
            } else {
                first = false;
            }
            buffer.append("\n        ");
            buffer.append(StringHelper.toJson("uri", input, true));
        }
        buffer.append("\n      ]");
        buffer.append(",");
        buffer.append("\n      \"outputs\": [");
        Set<String> outputs = RouteDefinitionHelper.gatherAllEndpointUris(this, route, false, true, includeDynamic);
        first = true;
        for (String output : outputs) {
            if (!first) {
                buffer.append(",");
            } else {
                first = false;
            }
            buffer.append("\n        ");
            buffer.append(StringHelper.toJson("uri", output, true));
        }
        buffer.append("\n      ]");
    }
    if (!firstRoute) {
        buffer.append("\n    }");
    }
    buffer.append("\n  }\n}\n");
    return buffer.toString();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611