Exemplo n.º 1
0
    /** Loops on processing a client forever */
    public void run() {
      TProcessor processor = null;
      TTransport inputTransport = null;
      TTransport outputTransport = null;
      TProtocol inputProtocol = null;
      TProtocol outputProtocol = null;
      try {
        processor = processorFactory_.getProcessor(client_);
        inputTransport = inputTransportFactory_.getTransport(client_);
        outputTransport = outputTransportFactory_.getTransport(client_);
        inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
        outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
        // we check stopped_ first to make sure we're not supposed to be shutting
        // down. this is necessary for graceful shutdown.
        while (!stopped_ && processor.process(inputProtocol, outputProtocol)) {}
      } catch (TTransportException ttx) {
        // Assume the client died and continue silently
      } catch (TException tx) {
        LOGGER.error("Thrift error occurred during processing of message.", tx);
      } catch (Exception x) {
        LOGGER.error("Error occurred during processing of message.", x);
      }

      if (inputTransport != null) {
        inputTransport.close();
      }

      if (outputTransport != null) {
        outputTransport.close();
      }
    }
 public void shutdown() {
   try {
     running = false;
     jedis.disconnect();
   } catch (Throwable t) {
     LOGGER.warn(t.getMessage(), t);
   }
 }
 @Override
 public void onMessage(String key, String msg) {
   if (LOGGER.isInfoEnabled()) {
     LOGGER.info("redis event: " + key + " = " + msg);
   }
   if (msg.equals(Constants.REGISTER) || msg.equals(Constants.UNREGISTER)) {
     try {
       Jedis jedis = jedisPool.getResource();
       try {
         doNotify(jedis, key);
       } finally {
         jedis.close();
       }
     } catch (Throwable t) {
       LOGGER.error(t.getMessage(), t);
     }
   }
 }
 @Override
 public void run() {
   try {
     while (running) {
       int retryTimes = 0;
       for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
         try {
           JedisPool jedisPool = entry.getValue();
           jedis = jedisPool.getResource();
           if (listenNodePath.equals(monitorId) && !redisAvailable) {
             redisAvailable = true;
             appContext.getRegistryStatMonitor().setAvailable(redisAvailable);
           }
           try {
             retryTimes = 0;
             jedis.subscribe(new NotifySub(jedisPool), listenNodePath); // 阻塞
             break;
           } finally {
             jedis.close();
           }
         } catch (Throwable t) { // 重试另一台
           LOGGER.warn(
               "Failed to subscribe node from redis registry. registry: " + entry.getKey(), t);
           if (++retryTimes % jedisPools.size() == 0) {
             // 如果在所有redis都不可用,需要休息一会,避免空转占用过多cpu资源
             sleep(reconnectPeriod);
             if (listenNodePath.equals(monitorId) && redisAvailable) {
               redisAvailable = false;
               appContext.getRegistryStatMonitor().setAvailable(redisAvailable);
             }
           }
         }
       }
     }
   } catch (Throwable t) {
     LOGGER.error(t.getMessage(), t);
   }
 }
    @Override
    public void run() {
      while (provider.isRunning()) {
        ResponseList<Post> postResponseList;
        try {
          postResponseList = client.getFeed(id);

          Set<Post> update = Sets.newHashSet(postResponseList);
          Set<Post> repeats = Sets.intersection(priorPollResult, Sets.newHashSet(update));
          Set<Post> entrySet = Sets.difference(update, repeats);
          LOGGER.debug(
              this.id
                  + " response: "
                  + update.size()
                  + " previous: "
                  + repeats.size()
                  + " new: "
                  + entrySet.size());
          for (Post item : entrySet) {
            String json = DataObjectFactory.getRawJSON(item);
            org.apache.streams.facebook.Post post =
                mapper.readValue(json, org.apache.streams.facebook.Post.class);
            try {
              lock.readLock().lock();
              ComponentUtils.offerUntilSuccess(new StreamsDatum(post), providerQueue);
              countersCurrent.incrementAttempt();
            } finally {
              lock.readLock().unlock();
            }
          }
          priorPollResult = update;
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          try {
            Thread.sleep(configuration.getPollIntervalMillis());
          } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
          }
        }
      }
    }