当前位置: 首页>>代码示例>>Java>>正文


Java Subject.asObservable方法代码示例

本文整理汇总了Java中rx.subjects.Subject.asObservable方法的典型用法代码示例。如果您正苦于以下问题:Java Subject.asObservable方法的具体用法?Java Subject.asObservable怎么用?Java Subject.asObservable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rx.subjects.Subject的用法示例。


在下文中一共展示了Subject.asObservable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import rx.subjects.Subject; //导入方法依赖的package包/类
/** @see BinderFactory#create(AgentID, Class) */
@Override
public synchronized GuiceBinder create(final AgentID agentID,
		final Class<? extends Agent> agentType) // throws CoalaException
{
	final GuiceBinder cached = this.binderCache.get(agentID);
	if (cached != null)
	{
		LOG.warn("UNEXPECTED: re-using binder previously created for agent: "
				+ agentID);
		return cached;
	}
	if (getConfig() == null)
	{
		throw CoalaExceptionFactory.VALUE_NOT_CONFIGURED.createRuntime(
				"config",
				"use BinderFactory#initialize(BinderFactoryConfig)");
	}

	final AgentStatusUpdate defaultValue = new AgentStatusUpdate()
	{

		@Override
		public AgentID getAgentID()
		{
			return agentID;
		}

		@Override
		public AgentStatus<?> getStatus()
		{
			return BasicAgentStatus.CREATED;
		}
		
		@Override
		public String toString()
		{
			return JsonUtil.toJSONString(this);
		}
	};
	
	final Subject<AgentStatusUpdate, AgentStatusUpdate> behaviorSubject = BehaviorSubject
			.create(defaultValue);

	this.statusUpdates.filter(new Func1<AgentStatusUpdate, Boolean>()
	{
		@Override
		public Boolean call(final AgentStatusUpdate update)
		{
			return update.getAgentID().equals(agentID);
		}
	}).subscribe(behaviorSubject);

	final GuiceBinder result = new GuiceBinder(getConfig(), agentID,
			agentType, behaviorSubject.asObservable());

	this.binderCache.put(agentID, result);
	LOG.trace("Cached new binder for agent: " + agentID);

	return result;
}
 
开发者ID:krevelen,项目名称:coala,代码行数:62,代码来源:GuiceBinderFactory.java

示例2: bootAgent

import rx.subjects.Subject; //导入方法依赖的package包/类
@Schedulable(ADD_PROCESS_MANAGER_AGENT)
protected synchronized Observable<AgentStatusUpdate> bootAgent(
		final AgentID agentID, final Class<? extends Agent> agentType,
		// final BasicAgentStatus blockSimUntilState,
		final Job<?> next) throws Exception
{
	if (next == null) // no need to sleep sim, nothing to schedule next
		return getBooter().createAgent(agentID, agentType);

	final CountDownLatch latch = new CountDownLatch(1);
	final Subject<AgentStatusUpdate, AgentStatusUpdate> status = ReplaySubject
			.create();
	status.subscribe(new Observer<AgentStatusUpdate>()
	{
		/** */
		private boolean success = false;

		@Override
		public void onNext(final AgentStatusUpdate update)
		{
			LOG().trace("Got child agent update: " + update);
			if (update.getStatus().isFailedStatus())
			{
				LOG().warn("Child agent failed: " + update.getAgentID());
				latch.countDown();
			} else if (update.getStatus().isInitializedStatus()// .equals(blockSimUntilState)
			)
			{
				LOG().info(
						"Child agent " + agentID
								+ " reached unblock status: "
								+ update.getStatus());
				// first schedule/block, then countdown/yield
				getSimulator().schedule(next,
						Trigger.createAbsolute(getTime()));
				success = true;
				latch.countDown(); // yield
			}
		}

		@Override
		public void onCompleted()
		{
			if (success)
				return;
			LOG().warn(
					"Child agent died but never reached blockable status"
							+ ", scheduling next job now");
			getSimulator()
					.schedule(next, Trigger.createAbsolute(getTime()));
			latch.countDown();
		}

		@Override
		public void onError(final Throwable e)
		{
			e.printStackTrace();
		}
	});

	getSimulator().schedule(
			ProcedureCall.create(this, this, AWAIT_METHOD_ID, latch,
					agentID), Trigger.createAbsolute(getTime()));

	getBooter().createAgent(agentID, agentType).subscribe(status);

	return status.asObservable();
}
 
开发者ID:krevelen,项目名称:coala,代码行数:69,代码来源:AbstractActorRole.java


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