Top Fields Constructors Methods
org.osgi.util.pushstream

pack-priv Class SimplePushEventSourceImpl<T, U extends BlockingQueue<PushEvent<? extends T>>>

extends Object
implements SimplePushEventSource<T>
Class Inheritance
All Implemented Interfaces
org.osgi.util.pushstream.SimplePushEventSource, java.lang.AutoCloseable, org.osgi.util.pushstream.PushEventSource
Static Imports
java.util.Collections.emptyList, java.util.concurrent.TimeUnit.NANOSECONDS, java.util.stream.Collectors.toList

Field Summary

Modifier and TypeField and Description
private boolean
private final List<PushEventConsumer<? super T>>
private Deferred<Void>
private final Object
private final Runnable
private final int
private final PromiseFactory
private final U
private final QueuePolicy<T, U>
private final PromiseFactory
private final Semaphore
private boolean

Constructor Summary

AccessConstructor and Description
public
SimplePushEventSourceImpl(PromiseFactory promiseFactory, QueuePolicy<T, U> queuePolicy, U queue, int parallelism, Runnable onClose)

Method Summary

Modifier and TypeMethod and Description
public void
private void
close(PushEvent<T> event)

private void
closeConsumer(PushEventConsumer<? super T> pec, PushEvent<T> event)

private Promise<Void>
public Promise<Void>
connectPromise()

Implements org.osgi.util.pushstream.SimplePushEventSource.connectPromise.

This method can be used to delay event generation until an event source has connected.

private Promise<Long>
deliver(List<PushEventConsumer<? super T>> toCall, PushEvent<T> event)

private Promise<Long>
doCall(PushEvent<T> event, PushEventConsumer<? super T> pec)

private void
doSend(PushEventConsumer<? super T> pec, PushEvent<T> event)

private Promise<Long>
public void
endOfStream()

Implements org.osgi.util.pushstream.SimplePushEventSource.endOfStream.

Close this source for now, but potentially reopen it later.

private void
public void
error(Throwable
the error
t
)

Implements org.osgi.util.pushstream.SimplePushEventSource.error.

Close this source for now, but potentially reopen it later.

private void
handleReset(boolean resetWait)

public boolean
public AutoCloseable
open(PushEventConsumer<? super T>
the consumer (not null)
pec
)

Implements org.osgi.util.pushstream.PushEventSource.open.

Open the asynchronous channel between the source and the consumer.

public void
publish(T t)

Implements org.osgi.util.pushstream.SimplePushEventSource.publish.

Asynchronously publish an event to this stream and all connected PushEventConsumer instances.

private long
safePush(PushEventConsumer<? super T> pec, PushEvent<T> event)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private boolean closed
connectedback to summary
private final List<PushEventConsumer<? super T>> connected
connectPromiseback to summary
private Deferred<Void> connectPromise
lockback to summary
private final Object lock
onCloseback to summary
private final Runnable onClose
parallelismback to summary
private final int parallelism
promiseFactoryback to summary
private final PromiseFactory promiseFactory
queueback to summary
private final U queue
queuePolicyback to summary
private final QueuePolicy<T, U> queuePolicy
sameThreadback to summary
private final PromiseFactory sameThread
semaphoreback to summary
private final Semaphore semaphore
waitForFinishesback to summary
private boolean waitForFinishes

Constructor Detail

SimplePushEventSourceImplback to summary
public SimplePushEventSourceImpl(PromiseFactory promiseFactory, QueuePolicy<T, U> queuePolicy, U queue, int parallelism, Runnable onClose)

Method Detail

closeback to summary
public void close()

Implements org.osgi.util.pushstream.SimplePushEventSource.close.

Doc from org.osgi.util.pushstream.SimplePushEventSource.close.

Close this source. Calling this method indicates that there will never be any more events published by it. Calling this method sends a close event to all connected consumers. After calling this method any PushEventConsumer that tries to open(PushEventConsumer) this source will immediately receive a close event, and will not see any remaining buffered events.

Annotations
@Override
closeback to summary
private void close(PushEvent<T> event)
closeConsumerback to summary
private void closeConsumer(PushEventConsumer<? super T> pec, PushEvent<T> event)
closedConnectPromiseback to summary
private Promise<Void> closedConnectPromise()
connectPromiseback to summary
public Promise<Void> connectPromise()

Implements org.osgi.util.pushstream.SimplePushEventSource.connectPromise.

Doc from org.osgi.util.pushstream.SimplePushEventSource.connectPromise.

This method can be used to delay event generation until an event source has connected. The returned promise will resolve as soon as one or more PushEventConsumer instances have opened the SimplePushEventSource.

The returned promise may already be resolved if this SimplePushEventSource already has connected consumers. If the SimplePushEventSource is closed before the returned Promise resolves then it will be failed with an IllegalStateException.

Note that the connected consumers are able to asynchronously close their connections to this SimplePushEventSource, and therefore it is possible that once the promise resolves this SimplePushEventSource may no longer be connected to any consumers.

Returns:Promise<Void>

A promise representing the connection state of this EventSource

Annotations
@Override
deliverback to summary
private Promise<Long> deliver(List<PushEventConsumer<? super T>> toCall, PushEvent<T> event)
doCallback to summary
private Promise<Long> doCall(PushEvent<T> event, PushEventConsumer<? super T> pec)
doSendback to summary
private void doSend(PushEventConsumer<? super T> pec, PushEvent<T> event)
doSendWithBackPressureback to summary
private Promise<Long> doSendWithBackPressure(PushEventConsumer<? super T> pec, PushEvent<T> event)
endOfStreamback to summary
public void endOfStream()

Implements org.osgi.util.pushstream.SimplePushEventSource.endOfStream.

Doc from org.osgi.util.pushstream.SimplePushEventSource.endOfStream.

Close this source for now, but potentially reopen it later. Calling this method asynchronously sends a close event to all connected consumers and then disconnects them. Any events previously queued by the publish(Object) method will be delivered before this close event.

After calling this method any PushEventConsumer that wishes may open(PushEventConsumer) this source, and will receive subsequent events.

Annotations
@Override
enqueueEventback to summary
private void enqueueEvent(PushEvent<T> event)
errorback to summary
public void error(Throwable t)

Implements org.osgi.util.pushstream.SimplePushEventSource.error.

Doc from org.osgi.util.pushstream.SimplePushEventSource.error.

Close this source for now, but potentially reopen it later. Calling this method asynchronously sends an error event to all connected consumers and then disconnects them. Any events previously queued by the publish(Object) method will be delivered before this error event.

After calling this method any PushEventConsumer that wishes may open(PushEventConsumer) this source, and will receive subsequent events.

Parameters
t:Throwable

the error

Annotations
@Override
handleResetback to summary
private void handleReset(boolean resetWait)
isConnectedback to summary
public boolean isConnected()

Implements org.osgi.util.pushstream.SimplePushEventSource.isConnected.

Doc from org.osgi.util.pushstream.SimplePushEventSource.isConnected.

Determine whether there are any PushEventConsumers for this PushEventSource. This can be used to skip expensive event creation logic when there are no listeners.

Returns:boolean

true if any consumers are currently connected

Annotations
@Override
openback to summary
public AutoCloseable open(PushEventConsumer<? super T> pec) throws Exception

Implements org.osgi.util.pushstream.PushEventSource.open.

Doc from org.osgi.util.pushstream.PushEventSource.open.

Open the asynchronous channel between the source and the consumer. The call returns an AutoCloseable. This can be closed, and should close the channel, including sending a Close event if the channel was not already closed. The returned object must be able to be closed multiple times without sending more than one Close events.

Parameters
pec:PushEventConsumer<? super T>

the consumer (not null)

Returns:AutoCloseable

a AutoCloseable that can be used to close the stream

Annotations
@Override
publishback to summary
public void publish(T t)

Implements org.osgi.util.pushstream.SimplePushEventSource.publish.

Doc from org.osgi.util.pushstream.SimplePushEventSource.publish.

Asynchronously publish an event to this stream and all connected PushEventConsumer instances. When this method returns there is no guarantee that all consumers have been notified. Events published by a single thread will maintain their relative ordering, however they may be interleaved with events from other threads.

Annotations
@Override
safePushback to summary
private long safePush(PushEventConsumer<? super T> pec, PushEvent<T> event)
startWorkerback to summary
private void startWorker()
Annotations
@SuppressWarnings:unchecked, boxing