• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Subscriber类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中java.util.concurrent.Flow.Subscriber的典型用法代码示例。如果您正苦于以下问题:Java Subscriber类的具体用法?Java Subscriber怎么用?Java Subscriber使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Subscriber类属于java.util.concurrent.Flow包,在下文中一共展示了Subscriber类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: subscribe

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
@Override
public void subscribe(Subscriber<? super T> s) {
  subscriber = s;
  subscriber.onSubscribe(new Subscription() {
    
    @Override
    public void request(long count) {
      requested = true;
      if (item != null) {
        publish(item);
      }
    }
    
    @Override
    public void cancel() {
      subscriber = null;
    }
  });
  if (error != null) {
    publish(error);
  }
}
 
开发者ID:openknowledge,项目名称:reactive-jax-rs,代码行数:23,代码来源:SingleItemPublisher.java


示例2: findAllAsync

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
public Publisher<Customer> findAllAsync() throws IOException {
  String customers = IOUtils.toString(new FileReader("customers.json")).trim();
  final String customerData = customers.substring(1, customers.length() - 1);

  return new Publisher<Customer>() {
    @Override
    public void subscribe(Subscriber<? super Customer> subscriber) {
      asList(customerData.split("\\{"))
        .stream()
        .filter(s -> !s.isEmpty())
        .map(c -> c.substring(0, c.lastIndexOf('}')))
        .map(c -> c.split(","))
        .map(c -> {
          String firstName = c[0].substring(c[0].indexOf(':') + 3, c[0].length() - 1);
          String lastName = c[1].substring(c[1].indexOf(':') + 3, c[1].length() - 1);
          return new Customer(firstName, lastName);
        })
        .forEach(subscriber::onNext);
      subscriber.onComplete();
    }
  };
}
 
开发者ID:openknowledge,项目名称:reactive-jax-rs,代码行数:23,代码来源:CustomerRepository.java


示例3: publish

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
public void publish(T i) {
  if (requested && subscriber != null) {
    Subscriber<? super T> s = subscriber;
    subscriber = null;
    s.onNext(i);
    s.onComplete();
  } else {
    item = i;
  }
}
 
开发者ID:openknowledge,项目名称:reactive-jax-rs,代码行数:11,代码来源:SingleItemPublisher.java


示例4: subscribe

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
@Override
public void subscribe(Subscriber<? super byte[]> subscriber) {
  byte[] buffer = new byte[1024];
  subscriber.onSubscribe(new Subscription() {
    
    @Override
    public void request(long count) {
      
      try {
        for (long i = 0; i < count; i++) {
          int read = stream.read(buffer);
          byte[] item = buffer;
          if (read != buffer.length) {
            item = new byte[read];
            System.arraycopy(buffer, 0, item, 0, read);
          }
          subscriber.onNext(item);
        }
      } catch (IOException e) {
        subscriber.onError(e);
      }
    }
    
    @Override
    public void cancel() {
    }
  });
}
 
开发者ID:openknowledge,项目名称:reactive-jax-rs,代码行数:29,代码来源:InputStreamPublisher.java


示例5: NumberSubscription

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
public NumberSubscription(ExecutorService executor,Subscriber<? super Long> subscriber,long start_range,long stop_range) {
	// TODO Auto-generated constructor stub
	this.executor = executor;
	this.subscriber=subscriber;
	this.start_range=start_range;
	this.stop_range=stop_range;
}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:8,代码来源:NumberPublisher.java


示例6: main

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
public static void main(String[] args) {

		MyPublisher publisher=new MyPublisher();
		
		Subscriber<News> consumer1, consumer2;
		consumer1=new Consumer("Consumer 1");
		consumer2=new Consumer("Consumer 2");
		
		publisher.subscribe(consumer1);
		publisher.subscribe(consumer2);
		
		System.out.printf("Main: Start\n");
		
		News news=new News();
		news.setTitle("My first news");
		news.setContent("This is the content");
		news.setDate(new Date());

		publisher.publish(news);
		
		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		news=new News();
		news.setTitle("My second news");
		news.setContent("This is the content of the second news");
		news.setDate(new Date());
		publisher.publish(news);
		
		System.out.printf("Main: End\n");
		
	}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:36,代码来源:Main.java


示例7: createNewSubscriptionFor

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
private Sub createNewSubscriptionFor(Subscriber<? super Integer> subscriber) {
	int startValue = subscriptions.stream()
			.mapToInt(sub -> sub.nextValue.get())
			.min()
			.orElse(0);
	return new Sub(subscriber, startValue);
}
 
开发者ID:CodeFX-org,项目名称:demo-java-9,代码行数:8,代码来源:IncrementingPublisher.java


示例8: subscribe

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
@Override
public void subscribe(Subscriber<? super Long> subscriber) {
	// TODO Auto-generated method stub
	subscriber.onSubscribe(new NumberSubscription(executor,subscriber,start_range,stop_range));

}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:7,代码来源:NumberPublisher.java


示例9: subscribe

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
@Override
public void subscribe(Subscriber<? super T> s) {
    s.onSubscribe(new JustSubscription<T>(s, value));
}
 
开发者ID:akarnokd,项目名称:jdk-9-experiments,代码行数:5,代码来源:FxJust.java


示例10: JustSubscription

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
public JustSubscription(Subscriber<? super T> actual, T value) {
    this.actual = actual;
    this.value = value;
}
 
开发者ID:akarnokd,项目名称:jdk-9-experiments,代码行数:5,代码来源:FxJust.java


示例11: subscribe

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
@Override
public void subscribe(Subscriber<? super Integer> subscriber) {
	Sub subscription = createNewSubscriptionFor(subscriber);
	registerSubscription(subscription);
	subscriber.onSubscribe(subscription);
}
 
开发者ID:CodeFX-org,项目名称:demo-java-9,代码行数:7,代码来源:IncrementingPublisher.java


示例12: Sub

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
public Sub(Subscriber<? super Integer> subscriber, int startValue) {
	this.subscriber = subscriber;
	this.nextValue = new AtomicInteger(startValue);
	this.canceled = new AtomicBoolean(false);
}
 
开发者ID:CodeFX-org,项目名称:demo-java-9,代码行数:6,代码来源:IncrementingPublisher.java


示例13: subscribe

import java.util.concurrent.Flow.Subscriber; //导入依赖的package包/类
@Override
public void subscribe(Subscriber<? super News> subscriber) {
	
	ConsumerData consumerData=new ConsumerData();
	consumerData.setConsumer((Consumer)subscriber);
	
	MySubscription subscription=new MySubscription();
	consumerData.setSubscription(subscription);
	
	subscriber.onSubscribe(subscription);
	
	consumers.add(consumerData);
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:14,代码来源:MyPublisher.java



注:本文中的java.util.concurrent.Flow.Subscriber类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Blending类代码示例发布时间:2022-05-23
下一篇:
Java FacetsProvider类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap