Examples of Exchanger


Examples of com.sissi.server.exchange.Exchanger

  @Override
  public Exchanger activate(String host) {
    if (MongoUtils.success(this.config.collection().remove(this.build(host, false), WriteConcern.SAFE))) {
      // Double check 4 multi thread
      Exchanger exchanger = this.exchangers.remove(host);
      return exchanger != null ? exchanger : new NothingExchanger(host);
    }
    return new NothingExchanger(host);
  }
View Full Code Here

Examples of com.sissi.server.exchange.Exchanger

    }

    private Timeout timeout() {
      try (DBCursor cursor = BridgeExchangerContext.this.config.collection().find(BasicDBObjectBuilder.start(BridgeExchangerContext.this.date, BasicDBObjectBuilder.start("$lt", System.currentTimeMillis() - BridgeExchangerContext.this.timeout).get()).get(), BridgeExchangerContext.this.filter)) {
        while (cursor.hasNext()) {
          Exchanger exchanger = BridgeExchangerContext.this.activate(MongoUtils.asString(DBObject.class.cast(cursor.next()), Dictionary.FIELD_HOST));
          // Double check 4 multi thread
          if (exchanger != null) {
            BridgeExchangerContext.this.log.warn("Timeout socks: " + exchanger.host());
            exchanger.close(Terminal.ALL);
          }
        }
      }
      return this;
    }
View Full Code Here

Examples of java.util.concurrent.Exchanger

                target = endpoint.getQueue() + "/t=" + endpoint.getConfiguration().getWaitTimeMs();
            } else {
                target = endpoint.getQueue();
            }

            @SuppressWarnings("rawtypes")
            Exchanger exchanger = null;
            while (isRunAllowed() && !shutdownPending) {
                if (concurrent) {
                    // Wait until an exchanger is available, indicating that a
                    // handler thread is ready to handle the next request.
                    // Don't read from kestrel until we know a handler is ready.
                    try {
                        exchanger = exchangerQueue.take();
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
                        }
                        continue;
                    }

                    // We have the exchanger, so there's a handler thread ready
                    // to handle whatever we may read...so read the next object
                    // from the queue.
                }

                // Poll kestrel until we get an object back
                Object value = null;
                while (isRunAllowed() && !shutdownPending) {
                    log.trace("Polling {}", target);
                    try {
                        value = memcachedClient.get(target);
                        if (value != null) {
                            break;
                        }
                    } catch (Exception e) {
                        if (isRunAllowed() && !shutdownPending) {
                            getExceptionHandler().handleException("Failed to get object from kestrel", e);
                        }
                    }

                    // We didn't get a value back from kestrel
                    if (isRunAllowed() && !shutdownPending) {
                        if (endpoint.getConfiguration().getWaitTimeMs() > 0) {
                            // Kestrel did the blocking for us
                        } else {
                            // We're doing non-blocking get, so in between we
                            // should at least sleep some short period of time
                            // so this loop doesn't go nuts so tightly.
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ignored) {
                            }
                        }
                    }
                }

                log.trace("Got object from {}", target);

                if (concurrent) {
                    // Pass the object to the handler thread via the exchanger.
                    // The handler will take it from there.
                    try {
                        exchanger.exchange(value);
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
                        }
                        continue;
View Full Code Here

Examples of java.util.concurrent.Exchanger

                target = endpoint.getQueue() + "/t=" + endpoint.getConfiguration().getWaitTimeMs();
            } else {
                target = endpoint.getQueue();
            }

            Exchanger exchanger = null;
            while (isRunAllowed() && !shutdownPending) {
                if (concurrent) {
                    // Wait until an exchanger is available, indicating that a
                    // handler thread is ready to handle the next request.
                    // Don't read from kestrel until we know a handler is ready.
                    try {
                        exchanger = exchangerQueue.take();
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? " + (isStopping() || isStopped()));
                        }
                        continue;
                    }

                    // We have the exchanger, so there's a handler thread ready
                    // to handle whatever we may read...so read the next object
                    // from the queue.
                }

                // Poll kestrel until we get an object back
                Object value = null;
                while (isRunAllowed() && !shutdownPending) {
                    if (log.isTraceEnabled()) {
                        log.trace("Polling " + target);
                    }
                    try {
                        value = memcachedClient.get(target);
                        if (value != null) {
                            break;
                        }
                    } catch (Exception e) {
                        if (isRunAllowed() && !shutdownPending) {
                            getExceptionHandler().handleException("Failed to get object from kestrel", e);
                        }
                    }

                    // We didn't get a value back from kestrel
                    if (isRunAllowed() && !shutdownPending) {
                        if (endpoint.getConfiguration().getWaitTimeMs() > 0) {
                            // Kestrel did the blocking for us
                        } else {
                            // We're doing non-blocking get, so in between we
                            // should at least sleep some short period of time
                            // so this loop doesn't go nuts so tightly.
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ignored) {
                            }
                        }
                    }
                }

                if (log.isTraceEnabled()) {
                    log.trace("Got object from " + target);
                }

                if (concurrent) {
                    // Pass the object to the handler thread via the exchanger.
                    // The handler will take it from there.
                    try {
                        exchanger.exchange(value);
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? " + (isStopping() || isStopped()));
                        }
                        continue;
View Full Code Here

Examples of java.util.concurrent.Exchanger

                target = endpoint.getQueue() + "/t=" + endpoint.getConfiguration().getWaitTimeMs();
            } else {
                target = endpoint.getQueue();
            }

            Exchanger exchanger = null;
            while (isRunAllowed() && !shutdownPending) {
                if (concurrent) {
                    // Wait until an exchanger is available, indicating that a
                    // handler thread is ready to handle the next request.
                    // Don't read from kestrel until we know a handler is ready.
                    try {
                        exchanger = exchangerQueue.take();
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
                        }
                        continue;
                    }

                    // We have the exchanger, so there's a handler thread ready
                    // to handle whatever we may read...so read the next object
                    // from the queue.
                }

                // Poll kestrel until we get an object back
                Object value = null;
                while (isRunAllowed() && !shutdownPending) {
                    log.trace("Polling {}", target);
                    try {
                        value = memcachedClient.get(target);
                        if (value != null) {
                            break;
                        }
                    } catch (Exception e) {
                        if (isRunAllowed() && !shutdownPending) {
                            getExceptionHandler().handleException("Failed to get object from kestrel", e);
                        }
                    }

                    // We didn't get a value back from kestrel
                    if (isRunAllowed() && !shutdownPending) {
                        if (endpoint.getConfiguration().getWaitTimeMs() > 0) {
                            // Kestrel did the blocking for us
                        } else {
                            // We're doing non-blocking get, so in between we
                            // should at least sleep some short period of time
                            // so this loop doesn't go nuts so tightly.
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ignored) {
                            }
                        }
                    }
                }

                log.trace("Got object from {}", target);

                if (concurrent) {
                    // Pass the object to the handler thread via the exchanger.
                    // The handler will take it from there.
                    try {
                        exchanger.exchange(value);
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
                        }
                        continue;
View Full Code Here

Examples of java.util.concurrent.Exchanger

                target = endpoint.getQueue() + "/t=" + endpoint.getConfiguration().getWaitTimeMs();
            } else {
                target = endpoint.getQueue();
            }

            @SuppressWarnings("rawtypes")
            Exchanger exchanger = null;
            while (isRunAllowed() && !shutdownPending) {
                if (concurrent) {
                    // Wait until an exchanger is available, indicating that a
                    // handler thread is ready to handle the next request.
                    // Don't read from kestrel until we know a handler is ready.
                    try {
                        exchanger = exchangerQueue.take();
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
                        }
                        continue;
                    }

                    // We have the exchanger, so there's a handler thread ready
                    // to handle whatever we may read...so read the next object
                    // from the queue.
                }

                // Poll kestrel until we get an object back
                Object value = null;
                while (isRunAllowed() && !shutdownPending) {
                    log.trace("Polling {}", target);
                    try {
                        value = memcachedClient.get(target);
                        if (value != null) {
                            break;
                        }
                    } catch (Exception e) {
                        if (isRunAllowed() && !shutdownPending) {
                            getExceptionHandler().handleException("Failed to get object from kestrel", e);
                        }
                    }

                    // We didn't get a value back from kestrel
                    if (isRunAllowed() && !shutdownPending) {
                        if (endpoint.getConfiguration().getWaitTimeMs() > 0) {
                            // Kestrel did the blocking for us
                        } else {
                            // We're doing non-blocking get, so in between we
                            // should at least sleep some short period of time
                            // so this loop doesn't go nuts so tightly.
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ignored) {
                            }
                        }
                    }
                }

                log.trace("Got object from {}", target);

                if (concurrent) {
                    // Pass the object to the handler thread via the exchanger.
                    // The handler will take it from there.
                    try {
                        exchanger.exchange(value);
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
                        }
                        continue;
View Full Code Here

Examples of java.util.concurrent.Exchanger

                target = endpoint.getQueue() + "/t=" + endpoint.getConfiguration().getWaitTimeMs();
            } else {
                target = endpoint.getQueue();
            }

            Exchanger exchanger = null;
            while (isRunAllowed() && !shutdownPending) {
                if (concurrent) {
                    // Wait until an exchanger is available, indicating that a
                    // handler thread is ready to handle the next request.
                    // Don't read from kestrel until we know a handler is ready.
                    try {
                        exchanger = exchangerQueue.take();
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
                        }
                        continue;
                    }

                    // We have the exchanger, so there's a handler thread ready
                    // to handle whatever we may read...so read the next object
                    // from the queue.
                }

                // Poll kestrel until we get an object back
                Object value = null;
                while (isRunAllowed() && !shutdownPending) {
                    log.trace("Polling {}", target);
                    try {
                        value = memcachedClient.get(target);
                        if (value != null) {
                            break;
                        }
                    } catch (Exception e) {
                        if (isRunAllowed() && !shutdownPending) {
                            getExceptionHandler().handleException("Failed to get object from kestrel", e);
                        }
                    }

                    // We didn't get a value back from kestrel
                    if (isRunAllowed() && !shutdownPending) {
                        if (endpoint.getConfiguration().getWaitTimeMs() > 0) {
                            // Kestrel did the blocking for us
                        } else {
                            // We're doing non-blocking get, so in between we
                            // should at least sleep some short period of time
                            // so this loop doesn't go nuts so tightly.
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ignored) {
                            }
                        }
                    }
                }

                log.trace("Got object from {}", target);

                if (concurrent) {
                    // Pass the object to the handler thread via the exchanger.
                    // The handler will take it from there.
                    try {
                        exchanger.exchange(value);
                    } catch (InterruptedException e) {
                        if (log.isDebugEnabled()) {
                            log.debug("Interrupted, are we stopping? {}", isStopping() || isStopped());
                        }
                        continue;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.