Package com.sissi.looper.impl

Source Code of com.sissi.looper.impl.FeedLooper

package com.sissi.looper.impl;

import java.util.concurrent.Future;

import com.sissi.feed.Feeder;
import com.sissi.looper.Looper;
import com.sissi.protocol.Protocol;
import com.sissi.thread.impl.ExecuteInterval;

/**
* @author kim 2014年4月14日
*/
abstract class FeedLooper implements Looper {

  private final ExecuteInterval interval;

  private final Future<?> future;

  private final Feeder feeder;

  FeedLooper(ExecuteInterval interval, Future<?> future, Feeder feeder) {
    super();
    this.interval = interval;
    this.future = future;
    this.feeder = feeder;
  }

  /**
   * 获取或堵塞
   *
   * @throws Exception
   */
  protected void getAndFeed() throws Exception {
    Protocol protocol = Protocol.class.cast(this.future.get(this.interval.getInterval(), this.interval.getUnit()));
    if (protocol != null) {
      this.feeder.feed(protocol);
    }
  }
}
TOP

Related Classes of com.sissi.looper.impl.FeedLooper

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.