Search in sources :

Example 1 with CachedScheduledThreadPool

use of org.vesalainen.util.concurrent.CachedScheduledThreadPool in project NMEAParser by tvesalainen.

the class N2KGatewayT method test.

@Test
public void test() throws IOException, InterruptedException, ExecutionException {
    Path in = Paths.get("C:\\Users\\tkv\\share", "candump.txt");
    Path out = Paths.get("C:\\Temp", "can2nmea.txt");
    N2KGateway gw = N2KGateway.getInstance("can1", in, out, new CachedScheduledThreadPool());
    gw.startAndWait();
}
Also used : Path(java.nio.file.Path) N2KGateway(org.vesalainen.nmea.router.endpoint.n2kgw.N2KGateway) CachedScheduledThreadPool(org.vesalainen.util.concurrent.CachedScheduledThreadPool) Test(org.junit.Test)

Example 2 with CachedScheduledThreadPool

use of org.vesalainen.util.concurrent.CachedScheduledThreadPool in project NMEAParser by tvesalainen.

the class AISLogFileTest method test1.

@Test
public void test1() throws IOException, InterruptedException {
    CachedScheduledThreadPool executor = new CachedScheduledThreadPool();
    AISLogFile log = new AISLogFile(path, 80, executor);
    log.format("qwertyuiopölkjhgfdasxcvbn");
    log.format("qwertyuiopölkjhgfdasxcvbn");
    log.format("qwertyuiopölkjhgfdasxcvbn");
    log.format("qwertyuiopölkjhgfdasxcvbn");
    log.format("qwertyuiopölkjhgfdasxcvbn");
    log.flush();
    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.DAYS);
    List<Path> exp = CollectionHelp.create(gz1, path);
    assertEquals(exp, log.getPaths());
}
Also used : Path(java.nio.file.Path) CachedScheduledThreadPool(org.vesalainen.util.concurrent.CachedScheduledThreadPool) Test(org.junit.Test)

Example 3 with CachedScheduledThreadPool

use of org.vesalainen.util.concurrent.CachedScheduledThreadPool in project NMEAParser by tvesalainen.

the class AISServiceT method test1.

@Test
public void test1() throws IOException, InterruptedException {
    CachedScheduledThreadPool executor = new CachedScheduledThreadPool();
    NMEAService nmeaService = new NMEAService("224.0.0.3", 10110, executor);
    Path dir = Paths.get("c:\\temp");
    AISService aisService = AISService.getInstance(nmeaService, dir, 10, 1024 * 1024, executor);
    nmeaService.start();
    while (true) {
        Thread.sleep(10000);
        System.err.println();
        Collection<AISTarget> liveList = aisService.getLiveList();
        liveList.forEach((t) -> testAISTarget(t));
    }
// aisService.addObserver((s, m, t)->System.err.println(s+" "+m));
// Thread.sleep(100000000);
}
Also used : Path(java.nio.file.Path) CachedScheduledThreadPool(org.vesalainen.util.concurrent.CachedScheduledThreadPool) NMEAService(org.vesalainen.parsers.nmea.NMEAService) Test(org.junit.Test)

Example 4 with CachedScheduledThreadPool

use of org.vesalainen.util.concurrent.CachedScheduledThreadPool in project NMEAParser by tvesalainen.

the class CommandLine method start.

private void start() throws IOException, InterruptedException, JAXBException, Exception {
    config("starting NMEA Server");
    Path configfile = getArgument("configuration file");
    Config config = new Config(configfile);
    String address = config.getNmeaMulticastAddress();
    int nmeaPort = config.getNmeaMulticastPort();
    int httpPort = config.getHttpPort();
    config("NMEA Multicast Address=%s", address);
    config("NMEA Multicast Port=%s", nmeaPort);
    config("HTTP Port=%s", httpPort);
    CachedScheduledThreadPool executor = new CachedScheduledThreadPool(64);
    config("ThreadPool started %s", executor);
    NMEAService nmeaService = new NMEAService(address, nmeaPort, executor);
    PropertyServer propertyServer = new PropertyServer(Clock.systemDefaultZone(), config, executor);
    nmeaService.addNMEAObserver(propertyServer);
    nmeaService.start();
    config("NMEA Service started");
    JavaUtilLog log = new JavaUtilLog();
    // make jetty use java.util.logger
    Log.setLog(log);
    Server server = new Server(httpPort);
    HandlerList handlers = new HandlerList();
    ServletContextHandler context = new ServletContextHandler();
    context.addServlet(ResourceServlet.class, "/");
    ServletHolder holder = new ServletHolder(SseServlet.class);
    holder.setAsyncSupported(true);
    context.addServlet(holder, "/sse");
    context.addServlet(ResourceServlet.class, "*.js");
    context.addServlet(ResourceServlet.class, "*.css");
    context.addServlet(ResourceServlet.class, "*.gif");
    context.addServlet(ResourceServlet.class, "*.png");
    context.addServlet(ResourceServlet.class, "*.ico");
    context.addServlet(PrefsServlet.class, "/prefs");
    context.addServlet(I18nServlet.class, "/i18n");
    SessionHandler sessionHandler = new SessionHandler();
    context.setSessionHandler(sessionHandler);
    handlers.addHandler(context);
    server.setHandler(handlers);
    server.setSessionIdManager(new DefaultSessionIdManager(server));
    ServletContext servletContext = context.getServletContext().getContext("/sse");
    servletContext.setAttribute(PropertyServer.class.getName(), propertyServer);
    server.start();
    executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
Also used : Path(java.nio.file.Path) HandlerList(org.eclipse.jetty.server.handler.HandlerList) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) CachedScheduledThreadPool(org.vesalainen.util.concurrent.CachedScheduledThreadPool) JavaUtilLog(org.eclipse.jetty.util.log.JavaUtilLog) ServletContext(javax.servlet.ServletContext) NMEAService(org.vesalainen.parsers.nmea.NMEAService) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 5 with CachedScheduledThreadPool

use of org.vesalainen.util.concurrent.CachedScheduledThreadPool in project NMEAParser by tvesalainen.

the class RouterManager method createPool.

private static CachedScheduledThreadPool createPool() {
    CachedScheduledThreadPool pool = new CachedScheduledThreadPool(MAX_POOL_SIZE);
    pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    return pool;
}
Also used : CachedScheduledThreadPool(org.vesalainen.util.concurrent.CachedScheduledThreadPool) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

CachedScheduledThreadPool (org.vesalainen.util.concurrent.CachedScheduledThreadPool)5 Path (java.nio.file.Path)4 Test (org.junit.Test)3 NMEAService (org.vesalainen.parsers.nmea.NMEAService)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 ServletContext (javax.servlet.ServletContext)1 Server (org.eclipse.jetty.server.Server)1 HandlerList (org.eclipse.jetty.server.handler.HandlerList)1 DefaultSessionIdManager (org.eclipse.jetty.server.session.DefaultSessionIdManager)1 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 JavaUtilLog (org.eclipse.jetty.util.log.JavaUtilLog)1 N2KGateway (org.vesalainen.nmea.router.endpoint.n2kgw.N2KGateway)1