Example #1
0
  public void testCustomRejectedExecutionHandler() {
    RejectedExecutionHandler handler =
        new RejectedExecutionHandler() {
          public void rejectedExecution(Runnable arg0, ThreadPoolExecutor arg1) {
            // nothing to do here
          }
        };

    ThreadingProfile profile = new ThreadingProfile();
    profile.setRejectedExecutionHandler(handler);
    ThreadPoolExecutor pool = profile.createPool("testPool");
    assertSame(handler, pool.getRejectedExecutionHandler());
  }
Example #2
0
  public void testCustomThreadFactory() {
    ThreadingProfile profile = new ThreadingProfile();

    ThreadFactory configuredFactory =
        new ThreadFactory() {
          public Thread newThread(Runnable r) {
            return null;
          }
        };

    profile.setThreadFactory(configuredFactory);
    ThreadPoolExecutor pool = profile.createPool();
    ThreadFactory returnedFactory = pool.getThreadFactory();
    assertSame(configuredFactory, returnedFactory);
  }
Example #3
0
  // @Override
  public void doStart() throws UMOException {
    // Connector property overrides any implied value
    this.setUseMultipleTransactedReceivers(connector.isCreateMultipleTransactedReceivers());

    ThreadingProfile tp = connector.getReceiverThreadingProfile();
    int numReceiversToStart = 1;

    if (this.isReceiveMessagesInTransaction()
        && this.isUseMultipleTransactedReceivers()
        && tp.isDoThreading()) {
      numReceiversToStart = connector.getNumberOfConcurrentTransactedReceivers();
    }

    for (int i = 0; i < numReceiversToStart; i++) {
      super.doStart();
    }
  }
Example #4
0
  protected void doConnect() throws Exception {
    httpServer = new Server();
    SocketListener socketListener =
        new SocketListener(new InetAddrPort(endpoint.getEndpointURI().getPort()));

    // apply Threading settings
    ThreadingProfile tp = connector.getReceiverThreadingProfile();
    socketListener.setMaxIdleTimeMs((int) tp.getThreadTTL());
    int threadsActive = tp.getMaxThreadsActive();
    int threadsMin = socketListener.getMinThreads();
    if (threadsMin >= threadsActive) {
      socketListener.setMinThreads(threadsActive - 1);
    }
    socketListener.setMaxThreads(threadsActive);
    // thread priorities are evil and gone from ThreadingProfile
    // (google for priority inversion)
    // socketListener.setThreadsPriority(tp.getThreadPriority());

    httpServer.addListener(socketListener);

    String path = endpoint.getEndpointURI().getPath();
    if (StringUtils.isEmpty(path)) {
      path = "/";
    }

    if (!path.endsWith("/")) {
      path += "/";
    }

    HttpContext context = httpServer.getContext("/");
    context.setRequestLog(null);

    ServletHandler handler = new ServletHandler();
    if ("rest".equals(endpoint.getEndpointURI().getScheme())) {
      handler.addServlet(
          "MuleRESTReceiverServlet", path + "*", MuleRESTReceiverServlet.class.getName());
    } else {
      handler.addServlet("JettyReceiverServlet", path + "*", JettyReceiverServlet.class.getName());
    }

    context.addHandler(handler);
    context.setAttribute("messageReceiver", this);
  }
Example #5
0
 public void testDefaultNamedThreadFactory() {
   ThreadingProfile profile = new ThreadingProfile();
   ThreadPoolExecutor pool = profile.createPool("myThreadPool");
   ThreadFactory returnedFactory = pool.getThreadFactory();
   assertTrue(returnedFactory instanceof NamedThreadFactory);
 }
Example #6
0
 public void testDefaultThreadFactory() {
   ThreadingProfile profile = new ThreadingProfile();
   ThreadPoolExecutor pool = profile.createPool();
   ThreadFactory returnedFactory = pool.getThreadFactory();
   assertTrue(returnedFactory.getClass().isInstance(Executors.defaultThreadFactory()));
 }
Example #7
0
  public void testPoolExhaustedActionStrings() {
    ThreadingProfile tp = new ThreadingProfile();

    tp.setPoolExhaustedActionString(null);
    assertEquals(ThreadingProfile.DEFAULT_POOL_EXHAUST_ACTION, tp.getPoolExhaustedAction());

    tp.setPoolExhaustedActionString("BAZ");
    assertEquals(ThreadingProfile.DEFAULT_POOL_EXHAUST_ACTION, tp.getPoolExhaustedAction());

    tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_WAIT");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_WAIT, tp.getPoolExhaustedAction());
    tp.setPoolExhaustedActionString("WAIT");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_WAIT, tp.getPoolExhaustedAction());

    tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_DISCARD");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_DISCARD, tp.getPoolExhaustedAction());
    tp.setPoolExhaustedActionString("DISCARD");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_DISCARD, tp.getPoolExhaustedAction());

    tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_DISCARD_OLDEST");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_DISCARD_OLDEST, tp.getPoolExhaustedAction());
    tp.setPoolExhaustedActionString("DISCARD_OLDEST");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_DISCARD_OLDEST, tp.getPoolExhaustedAction());

    tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_ABORT");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_ABORT, tp.getPoolExhaustedAction());
    tp.setPoolExhaustedActionString("ABORT");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_ABORT, tp.getPoolExhaustedAction());

    tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_RUN");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_RUN, tp.getPoolExhaustedAction());
    tp.setPoolExhaustedActionString("RUN");
    assertEquals(ThreadingProfile.WHEN_EXHAUSTED_RUN, tp.getPoolExhaustedAction());
  }