@Override
  public void configure(AtmosphereConfig config) {
    Object o = config.properties().get("shared");
    if (o != null) {
      isShared = Boolean.parseBoolean(o.toString());
    }

    if (isShared) {
      reaper = ExecutorsFactory.getScheduler(config);
    } else {
      reaper = Executors.newSingleThreadScheduledExecutor();
    }
    this.config = config;
  }
Ejemplo n.º 2
0
  public ChannelBufferPool(
      final int minIdle,
      final int writeBufferPoolSize,
      final long validationInterval,
      AtmosphereConfig config) {
    this.writeBufferPoolSize = writeBufferPoolSize;

    initialize(minIdle);

    if (writeBufferPoolSize != -1) {
      ExecutorsFactory.getScheduler(config)
          .scheduleWithFixedDelay(
              new Runnable() {
                @Override
                public void run() {
                  int size = pool.size();
                  if (size < minIdle) {
                    int sizeToBeAdded = minIdle - size;
                    for (int i = 0; i < sizeToBeAdded; i++) {
                      pool.add(createObject());
                    }
                  } else if (size > writeBufferPoolSize) {
                    int sizeToBeRemoved = size - writeBufferPoolSize;
                    for (int i = 0; i < sizeToBeRemoved; i++) {
                      pool.poll();
                    }
                  }
                }
              },
              validationInterval,
              validationInterval,
              TimeUnit.SECONDS);

      config.shutdownHook(
          new AtmosphereConfig.ShutdownHook() {
            @Override
            public void shutdown() {
              pool.clear();
            }
          });
    }
  }
  public void configure(AtmosphereConfig config) {
    this.config = config;

    String maxInactive = config.getInitParameter(MAX_INACTIVE);
    if (maxInactive != null) {
      maxInactiveTime = Long.parseLong(maxInactive);
    }

    if (maxInactiveTime > 0) {
      ExecutorsFactory.getScheduler(config)
          .scheduleAtFixedRate(
              new Runnable() {
                public void run() {
                  idleResources();
                }
              },
              0,
              2,
              TimeUnit.SECONDS);
    }
  }
Ejemplo n.º 4
0
 @Override
 public AsyncSupport complete(AtmosphereResourceImpl r) {
   final HttpEvent event = (HttpEvent) r.getRequest(false).getAttribute(HTTP_EVENT);
   // Prevent Deadlock
   // https://github.com/Atmosphere/atmosphere/issues/1782
   if (event != null) {
     if (!r.isResumed()) {
       ExecutorsFactory.getScheduler(config)
           .schedule(
               new Runnable() {
                 @Override
                 public void run() {
                   close(event);
                 }
               },
               500,
               TimeUnit.MILLISECONDS);
     } else {
       close(event);
     }
   }
   return this;
 }
Ejemplo n.º 5
0
 @AfterMethod
 public void unSet() throws Exception {
   config.destroy();
   ExecutorsFactory.reset(config);
   factory.destroy();
 }