Class StreamBaseClient
- java.lang.Object
-
- com.streambase.sb.client.StreamBaseClient
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
DeMUXStreamBaseClient
public class StreamBaseClient extends Object
A client used to subscribe to StreamBase streams and to send commands to the StreamBase Server. Note that this implementation is not synchronized. If instances of this class are accessed from multiple threads, access must be synchronized. With the exception of close(), the single threaded restriction dictates that no thread may reference the object - including enqueueing - while another thread is in dequeue(). If multiple threads subscribe to streams, it is recommended that they use separate instances of this class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceStreamBaseClient.ListEntityFlagsFlags used by the ListEntities call.classStreamBaseClient.SerializedTupleBufferA TupleBuffer which contains a byte buffer of serialized tuples including space for a network headerclassStreamBaseClient.TupleBufferClass for abstracting away where tuples come from, Buffers, Collections, and Single Enqueues.
-
Field Summary
Fields Modifier and Type Field Description protected com.streambase.sb.client.Admin_adminstatic intVARIABLE_RESPONSEUsed to signal that a command will return a variable number of responses
-
Constructor Summary
Constructors Constructor Description StreamBaseClient()Create a StreamBaseClient.StreamBaseClient(StreamBaseURI uri)Create a StreamBaseClient, connecting to the server at the provided URIStreamBaseClient(String uriStrings)Create a StreamBaseClient from one or more comma-separated URI stringsStreamBaseClient(List<StreamBaseURI> uris)Create a StreamBaseClient, connecting to the servers at the provided URIs.StreamBaseClient(List<StreamBaseURI> uris, ClientSettings settings)Create a StreamBaseClient, connecting to the servers at the provided URIs.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddConnectionStatusCallback(ConnectionStatusCallback callback)Track changes to the connection state.protected static StringassureNameStartsWithContainer(StreamProperties base, String logicalName)Ensure name starts with containerbooleancanDequeue()Return true if we can call dequeue without blocking.protected static voidcheckValidStreamname(String streamname)Validate stream namevoidclose()close the clientvoidclose(String msg)Flush all buffers and close the connection to the StreamBase server.DequeueResultdequeue()Dequeue a batch of tuples from a subscribed stream.DequeueResultdequeue(long timeoutMS)Dequeue a batch of tuples from a subscribed stream.Stringdescribe(String entityName)Return an XML description of a StreamBase entityvoidenableBuffering(int bufferSize)Turn on buffering with a default WakeAndFlushBuffer thread set to 250msvoidenableBuffering(int bufferSize, long flushIntervalMilliSeconds)Turn on buffering.voidenqueue(StreamProperties props, Tuple tuple)Enqueue a single Tuple onto a stream.voidenqueue(StreamProperties props, Collection<Tuple> tuples)Enqueue a collection of Tuples onto a stream.voidenqueue(String stream, Tuple tuple)Enqueue a single Tuple onto a stream.voidenqueue(String stream, Collection<Tuple> tuples)Enqueue a collection of Tuples onto a stream.voidflushAllBuffers()Flush any pending enqueue buffers.voidflushBuffer(StreamProperties props)Deprecated.useflushAllBuffers()to preserve inter-stream orderingvoidflushBuffer(String stream_name)Deprecated.useflushAllBuffers()to preserve inter-stream orderingSet<StreamProperties>getAllStreamProperties(EntityType type)Return all the StreamProperties available.Set<StreamProperties>getAllStreamProperties(EntityType type, CaptureTransformStrategy strategy)Return all the StreamProperties availableStringgetConnectionError()If the StreamBaseClient disconnected due to an internal error, return a message corresponding to the error, otherwise return null.byte[]getConnectionID()Return the Connection ID for this Client Connection.ConnectionStatusgetConnectionStatus()Return the current connection status of this StreamBaseClient.DequeueResult.InterceptorgetDequeueResultsInterceptor()Get the current dequeue results interceptor, or null if there is no current processor.ObjectgetDynamicVariable(String dynamicVariablePath)Get the given dynamic variableTuplegetDynamicVariables(String modulePath)Get a Tuple of all the dynamic variables on the given moduleintgetEnqueueBufferSize()Return the number of tuples in the enqueue bufferSchemagetSchemaByHash(byte[] hash)Return the Schema object for the given hash valueSchemagetSchemaByName(String name)Return the Schema object for the given name.SchemagetSchemaForStream(String streamName)Return the schema of a stream.ClientSettingsgetSettings()Return the settings for this clientStreamPropertiesgetStreamProperties(String streamName)Return the StreamProperties for the given stream nameStreamPropertiesgetStreamProperties(String streamName, CaptureTransformStrategy strategy)Return the StreamProperties for the given stream nameStreamPropertiesgetStreamPropertiesByHash(byte[] hash)Return the StreamProperties for the given hash StreamProperties are cached locally in the client.StreamPropertiesgetStreamPropertiesByHash(String hashHexString)Return the StreamProperties for the given hash StreamProperties are cached locally in the client.Set<String>getSubscribedStreamNames()Returns a Set of names of the Streams this client is currently subscribed to.longgetTupleDequeueCount()Returns the number of tuples this client has dequeued from the server.longgetTupleEnqueueCount()Returns the number of tuples this client has actually enqueued to the server.StreamBaseURIgetURI()Return the URI used by this Client.List<StreamBaseURI>getURIs()get all of the URI's for this clientstatic StringgetVersion()Get the version of this client, returned in the format specified byVersion.INFO_LINEprotected booleanhaModeOn()is HA mode onbooleanhasSchema(String schemaName)Returns whether or not a schema with the passed in schemaName is available; you can get this Schema by calling getSchemaByName.booleanhasStream(String streamName)Returns whether or not the client has a stream with the passed in name.booleanhasStreamProperties(String streamName)Returns whether or not a stream with the given name exists.booleanisClosed()Return true if the client connection is closed.booleanisSubscribed(StreamProperties stream)Return status if we are subscribed to the given streamString[]listEntities(EntityType entityType)Return an array of entity names for the given entity type.String[]listEntities(EntityType entityType, int flags)Return an array of entity names for the given entity type and flags.String[]listEntities(EntityType entityType, int flags, CaptureTransformStrategy strategy)Return an array of entity names for the given entity type and flags.String[]listEntities(EntityType entityType, CaptureTransformStrategy strategy)Return an array of entity names for the given entity type.String[]listEntities(String entityPath, int flags)Return an array of entity names for the given entity path.String[]listEntities(String entityPath, int flags, CaptureTransformStrategy strategy)Return an array of entity names for the given entity path.String[]operatorStatus(String containerName)Return the status of all the operators in the specified containerList<Tuple>readTable(String tablePath, int rowLimit)Return rows from a Query Table or Materialized Window.List<Tuple>readTable(String tablePath, int rowLimit, String predicate)Return rows from a Query Table or Materialized Window, applying an optional predicate to decide which rows are returned.voidremoveConnectionStatusCallback(ConnectionStatusCallback callback)Stop tracking changes to the connection state.StreamPropertiesresubscribe(StreamProperties props, String logicalstream, String predicate)Resubscribe to a stream with a predicate.StreamPropertiesresubscribe(String streamname, String logicalstream, String predicate)Resubscribe to a stream with a predicate.protected voidsetConnectionStatus(ConnectionStatus status, String additionalInfo)Set connection statusDequeueResult.InterceptorsetDequeueResultInterceptor(DequeueResult.Interceptor dri)Set the dequeue results interceptor for this client connection.voidsetDynamicVariable(String dynvarPath, Object value)Set the given dynamic variable to a new valuevoidsetQuiescentLimit(long timeoutMS)If more then timeoutMS milliseconds elapse without receiving data or a heart beat from the server, the client will close.String[]status()Return the status of the StreamBase ServerString[]status(boolean verbose)Return the status of the StreamBase ServerStreamPropertiessubscribe(StreamProperties props)Subscribe to a streamStreamPropertiessubscribe(StreamProperties props, String logicalstream, String predicate)Subscribe to a stream with a predicate.StreamPropertiessubscribe(String streamname)Subscribe to a streamStreamPropertiessubscribe(String streamName, CaptureTransformStrategy strategy)Subscribe to a streamStreamPropertiessubscribe(String streamName, CaptureTransformStrategy strategy, String logicalstream, String predicate)Subscribe to a stream with a predicate.StreamPropertiessubscribe(String streamname, String logicalstream, String predicate)Subscribe to a stream with a predicate.StreamProperties[]typecheck(String application)Typecheck (validate) the given StreamBase Application.StreamProperties[]typecheck(String application, boolean full)Typecheck (validate) the given StreamBase Application.voidunsubscribe(StreamProperties logicalProps)Unsubscribe from the given stream name.voidunsubscribe(String logicalStreamName)Unsubscribe from the given stream name.protected voidunsubscribeInternal(StreamProperties logicalProps)Un-subscribe from stream
-
-
-
Field Detail
-
VARIABLE_RESPONSE
public static final int VARIABLE_RESPONSE
Used to signal that a command will return a variable number of responses- See Also:
- Constant Field Values
-
_admin
protected final com.streambase.sb.client.Admin _admin
-
-
Constructor Detail
-
StreamBaseClient
public StreamBaseClient(String uriStrings) throws StreamBaseException
Create a StreamBaseClient from one or more comma-separated URI strings- Parameters:
uriStrings- The URIs to use, in string form; e.g., "sb://localhost:10000" or "sb://host1:10000,sb://host2"- Throws:
StreamBaseException- on connect errorURIException- on malformed or invalid URI- See Also:
StreamBaseURI
-
StreamBaseClient
public StreamBaseClient() throws StreamBaseException, URIExceptionCreate a StreamBaseClient. Connects to the URI found in thestreambase.uriproperty, or the system environment variableSTREAMBASE_SERVER, orStreamBaseURI.DEFAULT_URIif neither is defined.- Throws:
StreamBaseException- on connect errorURIException- on malformed or invalid URI- See Also:
StreamBaseURI.fromEnvironment()
-
StreamBaseClient
public StreamBaseClient(StreamBaseURI uri) throws StreamBaseException
Create a StreamBaseClient, connecting to the server at the provided URI- Parameters:
uri- The uri to connect to- Throws:
StreamBaseException- on connect error- See Also:
StreamBaseURI
-
StreamBaseClient
public StreamBaseClient(List<StreamBaseURI> uris) throws StreamBaseException
Create a StreamBaseClient, connecting to the servers at the provided URIs. This constructor is used to connect to StreamBase Servers configured in a High Availability setup.- Parameters:
uris- a list of URIs to connect to- Throws:
StreamBaseException- on connect error- See Also:
StreamBaseURI
-
StreamBaseClient
public StreamBaseClient(List<StreamBaseURI> uris, ClientSettings settings) throws StreamBaseException
Create a StreamBaseClient, connecting to the servers at the provided URIs. This constructor is used to connect to StreamBase Servers configured in a High Availability setup.- Parameters:
uris- a list of URIs to connect tosettings- client settings- Throws:
StreamBaseException- on connect error- Since:
- 7.1
- See Also:
StreamBaseURI
-
-
Method Detail
-
close
public void close() throws StreamBaseExceptionclose the client- Specified by:
closein interfaceAutoCloseable- Throws:
StreamBaseException- close failed
-
close
public void close(String msg) throws StreamBaseException
Flush all buffers and close the connection to the StreamBase server. StreamBaseClient memory, network, and thread resources are not released until close() is called.- Parameters:
msg-- Throws:
StreamBaseException
-
canDequeue
public boolean canDequeue()
Return true if we can call dequeue without blocking. This means that there is something to dequeue from the server. This dequeued item could be Tuples, a null (server shutdown) or an exception.- Returns:
- boolean if we can dequeue without blocking
-
isClosed
public boolean isClosed()
Return true if the client connection is closed. Once reported as closed, clients will never be reported as open again. Calling dequeue, enqueue, etc. on a closed client will result in an exception. This method is provided as a convenience, there is no need to determine if a client is closed before calling any of it's methods.- Returns:
- boolean if we can dequeue without blocking
-
dequeue
public DequeueResult dequeue() throws StreamBaseException
Dequeue a batch of tuples from a subscribed stream. This method will block. Will return null if the connection is closed.- Returns:
- a DequeueResult (or null) from any subscribed stream (only one stream per DequeueResult)
- Throws:
StreamBaseException- thrown on network or other errors
-
dequeue
public DequeueResult dequeue(long timeoutMS) throws StreamBaseException
Dequeue a batch of tuples from a subscribed stream. This method will block until there are tuples available or timeoutMS milliseconds have past. It will return null if the connection is closed. It will return an empty DequeueResult if timeoutMS milliseconds have past and no tuples have returned. A timeout_ms of zero will block indefinitely, or until a tuple arrives.- Parameters:
timeoutMS- timeout in milliseconds- Returns:
- a DequeueResult from any subscribed stream (only one stream per DequeueResult)
- Throws:
StreamBaseException- thrown on network or other errors
-
setDequeueResultInterceptor
public DequeueResult.Interceptor setDequeueResultInterceptor(DequeueResult.Interceptor dri)
Set the dequeue results interceptor for this client connection. This results interceptor replaces any existing results processor. To disable pre-processing of results, set the processor to null. This method cannot be safely called while another thread is calling dequeue().- Parameters:
dri- dequeue results interceptor for this client connection- Returns:
- the old dequeue results interceptor
-
getDequeueResultsInterceptor
public DequeueResult.Interceptor getDequeueResultsInterceptor()
Get the current dequeue results interceptor, or null if there is no current processor.- Returns:
- the current dequeue results interceptor
-
describe
public String describe(String entityName) throws StreamBaseException
Return an XML description of a StreamBase entity- Parameters:
entityName- the name of the entity to describe- Returns:
- an XML description of a StreamBase entity
- Throws:
StreamBaseException- thrown on network or other errors
-
enableBuffering
public void enableBuffering(int bufferSize, long flushIntervalMilliSeconds) throws StreamBaseExceptionTurn on buffering. A WakeAndFlushBuffer thread is only started if flushInterval > 0.- Parameters:
bufferSize- specifies the number of tuples to buffer before enqueueing. If set to a non-positive value, this call has no effectflushIntervalMilliSeconds- specifies the interval in milliseconds between wakeups of WakeAndFlushBuffer- Throws:
StreamBaseException- thrown on network or other errors
-
enableBuffering
public void enableBuffering(int bufferSize) throws StreamBaseExceptionTurn on buffering with a default WakeAndFlushBuffer thread set to 250ms- Parameters:
bufferSize- specifies the number of tuples to buffer before enqueueing. if a non-positive value is given, this call has no effect- Throws:
StreamBaseException- thrown on network or other errors- See Also:
enableBuffering(int, long)
-
enqueue
public void enqueue(String stream, Tuple tuple) throws StreamBaseException
Enqueue a single Tuple onto a stream. This method can block depending on network, or StreamBase server, congestion.Performance note: this method should be avoided where possible. Use
enqueue(StreamProperties, Tuple)instead.- Parameters:
stream- the name of the stream on which to enqueue the provided tuple.tuple- the Tuple to enqueue- Throws:
StreamBaseException- thrown on network or other errors- See Also:
enqueue(StreamProperties, Tuple)
-
enqueue
public void enqueue(StreamProperties props, Tuple tuple) throws StreamBaseException
Enqueue a single Tuple onto a stream. This method can block depending on network, or StreamBase server, congestion.- Parameters:
props- the StreamProperties for the stream to enqueue the tuple totuple- the Tuple to enqueue- Throws:
StreamBaseException- thrown on network or other errors
-
enqueue
public void enqueue(String stream, Collection<Tuple> tuples) throws StreamBaseException
Enqueue a collection of Tuples onto a stream. All tuples must be for the same stream. This method can block depending on network, or StreamBase server, congestion.Performance note: this method should be avoided where possible. Use
enqueue(StreamProperties, Collection)instead.- Parameters:
stream- the name of the stream on which to enqueue the provided tuples.tuples- a Collection of Tuples to enqueue. Note that the tuples will be modified as part of enqueue- Throws:
StreamBaseException- thrown on network or other errors- See Also:
enqueue(StreamProperties, Collection)
-
enqueue
public void enqueue(StreamProperties props, Collection<Tuple> tuples) throws StreamBaseException
Enqueue a collection of Tuples onto a stream. All tuples must be for the same stream. This method can block depending on network, or StreamBase server, congestion.- Parameters:
props- the StreamProperties for the stream to enqueue the tuples totuples- a Collection of Tuples to enqueue. Note that the tuples will be modified as part of enqueue- Throws:
StreamBaseException- thrown on network or other errors
-
flushAllBuffers
public void flushAllBuffers() throws StreamBaseExceptionFlush any pending enqueue buffers. This operation has no effect if buffering is not enabled.- Throws:
StreamBaseException- if there is an IO error while flushing the buffer
-
flushBuffer
public void flushBuffer(String stream_name) throws StreamBaseException
Deprecated.useflushAllBuffers()to preserve inter-stream orderingFlush any pending enqueue buffer for the stream name provided. This operation has no effect if buffering is not enabled or there is no buffer to flush for the given stream.Note: Note that this will cause inter-stream ordering to be interrupted.
- Parameters:
stream_name- the stream whose enqueue buffers to flush, if not empty- Throws:
StreamBaseException- if there is an IO error while flushing the buffer
-
flushBuffer
public void flushBuffer(StreamProperties props) throws StreamBaseException
Deprecated.useflushAllBuffers()to preserve inter-stream orderingFlush any pending enqueue buffer for theStreamPropertiesprovided. This operation has no effect if buffering is not enabled or there is no buffer to flush for the given stream.Note: Note that this will cause inter-stream ordering to be interrupted.
- Parameters:
props- the stream whose enqueue buffers to flush, if not empty- Throws:
StreamBaseException- if there is an IO error while flushing the buffer
-
setQuiescentLimit
public void setQuiescentLimit(long timeoutMS) throws StreamBaseExceptionIf more then timeoutMS milliseconds elapse without receiving data or a heart beat from the server, the client will close.- Parameters:
timeoutMS- - If no heart beat is received from the server in timeoutMS milliseconds, the server is considered unavailable. This only has effect if the server is configured to emit client heart beats. This is not a real-time detection mechanism, so generous timeout limits should be used. 0 disables quiescent server detection.- Throws:
StreamBaseException- thrown if the request limit is not at least two times the servers configured client heart beat rate.
-
getSchemaByHash
public Schema getSchemaByHash(byte[] hash) throws StreamBaseException
Return the Schema object for the given hash value- Parameters:
hash- a byte array that contains a hash value- Returns:
- The Schema object associated with the given hash value
- Throws:
StreamBaseException- thrown on network or other errors
-
hasSchema
public boolean hasSchema(String schemaName)
Returns whether or not a schema with the passed in schemaName is available; you can get this Schema by calling getSchemaByName.- Parameters:
schemaName- the name of the Schema to look up- Returns:
- true if a schema was found
- Since:
- 5.0
- See Also:
getSchemaByName(String)
-
getSchemaByName
public Schema getSchemaByName(String name) throws StreamBaseException
Return the Schema object for the given name. This will only succeed for named schemas. For anonymous schemas assigned to streams usegetStreamProperties(String).- Parameters:
name- the name of the Schema to lookup- Returns:
- the Schema for the given name
- Throws:
StreamBaseException- thrown on network or other errors
-
hasStreamProperties
public boolean hasStreamProperties(String streamName)
Returns whether or not a stream with the given name exists. You can get a StreamProperties for this stream by calling getStreamProperties.- Parameters:
streamName- the stream name to look for- Returns:
- true if a stream with the given name exists, false otherwise
- Since:
- 5.0
- See Also:
getStreamProperties(String)
-
getStreamProperties
public StreamProperties getStreamProperties(String streamName, CaptureTransformStrategy strategy) throws StreamBaseException
Return the StreamProperties for the given stream name- Parameters:
streamName- the name of a stream, that may be fully qualified (for example,mycontainer.MyInputSchema). When unqualified, the container from the URI the connection was established with is used, otherwiseStreamBaseURI.DEFAULT_CONTAINERis used.strategy- capture transform strategy- Returns:
- The StreamProperties object for the given stream name
- Throws:
StreamBaseException- thrown on network or other errors- Since:
- 7.2.6
-
getStreamProperties
public StreamProperties getStreamProperties(String streamName) throws StreamBaseException
Return the StreamProperties for the given stream name- Parameters:
streamName- the name of a stream, that may be fully qualified (for example,mycontainer.MyInputSchema). When unqualified, the container from the URI the connection was established with is used, otherwiseStreamBaseURI.DEFAULT_CONTAINERis used.- Returns:
- The StreamProperties object for the given stream name
- Throws:
StreamBaseException- thrown on network or other errors
-
assureNameStartsWithContainer
protected static String assureNameStartsWithContainer(StreamProperties base, String logicalName)
Ensure name starts with container- Parameters:
base- PropertieslogicalName- Name to validate- Returns:
- Fully qualified name
-
getStreamPropertiesByHash
public StreamProperties getStreamPropertiesByHash(String hashHexString) throws StreamBaseException
Return the StreamProperties for the given hash StreamProperties are cached locally in the client.- Parameters:
hashHexString- The Hash as a HexString- Returns:
- The StreamProperties object for the given name
- Throws:
StreamBaseException- thrown on network or other errors
-
getStreamPropertiesByHash
public StreamProperties getStreamPropertiesByHash(byte[] hash) throws StreamBaseException
Return the StreamProperties for the given hash StreamProperties are cached locally in the client.- Parameters:
hash- The Hash to lookup- Returns:
- The StreamProperties object for the given name
- Throws:
StreamBaseException- thrown on network or other errors
-
getAllStreamProperties
public Set<StreamProperties> getAllStreamProperties(EntityType type, CaptureTransformStrategy strategy) throws StreamBaseException
Return all the StreamProperties available- Parameters:
type- Can be STREAM, INPUT_STREAMS, or OUTPUT_STREAMSstrategy- the CaptureTransformStrategy to use. Can be FLATTEN or NEST- Returns:
- A Set of StreamProperties
- Throws:
StreamBaseException- thrown on network or other errors- Since:
- 7.2.6
-
getAllStreamProperties
public Set<StreamProperties> getAllStreamProperties(EntityType type) throws StreamBaseException
Return all the StreamProperties available. Uses CaptureTransformStrategy.FLATTEN- Parameters:
type- Can be STREAM, INPUT_STREAMS, or OUTPUT_STREAMS- Returns:
- A Set of StreamProperties
- Throws:
StreamBaseException- thrown on network or other errors
-
hasStream
public boolean hasStream(String streamName)
Returns whether or not the client has a stream with the passed in name. You can get the schema for this stream by calling getSchemaForStream- Parameters:
streamName-- Returns:
- true if the client has streamName
- Since:
- 5.0
- See Also:
getSchemaForStream(String)
-
getSchemaForStream
public Schema getSchemaForStream(String streamName) throws StreamBaseException
Return the schema of a stream.- Parameters:
streamName- the name of a stream, that may be fully qualified (for example,mycontainer.MyInputSchema). When unqualified, the container from the URI the connection was established with is used, otherwiseStreamBaseURI.DEFAULT_CONTAINERis used.- Returns:
- the schema of the stream
- Throws:
StreamBaseException- if the stream is not found, or on network errors
-
getVersion
public static String getVersion()
Get the version of this client, returned in the format specified byVersion.INFO_LINE- Returns:
- a version string
-
listEntities
public String[] listEntities(EntityType entityType, CaptureTransformStrategy strategy) throws StreamBaseException
Return an array of entity names for the given entity type. Equivalent tolistEntities(EntityType, int)withStreamBaseClient.ListEntityFlags.NO_FLAGSas the second argument. Note: if the container you are connected to does not exist when issuing this request, and this call is made without theStreamBaseClient.ListEntityFlags.ALL_CONTAINERSflag, the request will fail.- Parameters:
entityType- the entity type that the looking is being done forstrategy- the strategy to use for capture fields- Returns:
- an array of entity names for the given entity type
- Throws:
StreamBaseException- thrown on network or other errors- Since:
- 7.2.6
- See Also:
listEntities(String, int),EntityType,StreamBaseClient.ListEntityFlags
-
listEntities
public String[] listEntities(EntityType entityType) throws StreamBaseException
Return an array of entity names for the given entity type. Equivalent tolistEntities(EntityType, int)withStreamBaseClient.ListEntityFlags.NO_FLAGSas the second argument. Note: if the container you are connected to does not exist when issuing this request, and this call is made without theStreamBaseClient.ListEntityFlags.ALL_CONTAINERSflag, the request will fail.- Parameters:
entityType- the entity type that the looking is being done for- Returns:
- an array of entity names for the given entity type
- Throws:
StreamBaseException- thrown on network or other errors- See Also:
listEntities(String, int),EntityType,StreamBaseClient.ListEntityFlags
-
listEntities
public String[] listEntities(EntityType entityType, int flags, CaptureTransformStrategy strategy) throws StreamBaseException
Return an array of entity names for the given entity type and flags.Examples are as follows:
// list streams on container specified in StreamBaseURI given to StreamBaseClient client.listEntities(EntityType.STREAM, StreamBaseClient.ListEntityFlags.NO_FLAGS) // list operators on ALL containers client.listEntities(EntityType.OPERATOR, StreamBaseClient.ListEntityFlags.ALL_CONTAINERS)Note: if the container you are connected to does not exist when issuing this request, and this call is made without the
StreamBaseClient.ListEntityFlags.ALL_CONTAINERSflag, the request will fail.- Parameters:
entityType- the entity type that the looking is being done forflags- a combination of flags fromStreamBaseClient.ListEntityFlagsstrategy- the strategy to use for capture fields- Returns:
- an array of entity names for the given entity type
- Throws:
StreamBaseException- thrown on network or other errors- Since:
- 7.2.6
- See Also:
EntityType,StreamBaseClient.ListEntityFlags
-
listEntities
public String[] listEntities(EntityType entityType, int flags) throws StreamBaseException
Return an array of entity names for the given entity type and flags.Examples are as follows:
// list streams on container specified in StreamBaseURI given to StreamBaseClient client.listEntities(EntityType.STREAM, StreamBaseClient.ListEntityFlags.NO_FLAGS) // list operators on ALL containers client.listEntities(EntityType.OPERATOR, StreamBaseClient.ListEntityFlags.ALL_CONTAINERS)Note: if the container you are connected to does not exist when issuing this request, and this call is made without the
StreamBaseClient.ListEntityFlags.ALL_CONTAINERSflag, the request will fail.- Parameters:
entityType- the entity type that the looking is being done forflags- a combination of flags fromStreamBaseClient.ListEntityFlags- Returns:
- an array of entity names for the given entity type
- Throws:
StreamBaseException- thrown on network or other errors- See Also:
EntityType,StreamBaseClient.ListEntityFlags
-
listEntities
public String[] listEntities(String entityPath, int flags, CaptureTransformStrategy strategy) throws StreamBaseException
Return an array of entity names for the given entity path. The entityPath can be either a simple entity type: "streams" or a path that includes a container such as: "mycontainer.streams". Valid entity types are from theEntityTypeclassExamples are as follows:
// list streams on container specified in StreamBaseURI given to StreamBaseClient client.listEntities("streams", StreamBaseClient.ListEntityFlags.NO_FLAGS) // list streams on container "other" client.listEntities("other.streams", StreamBaseClient.ListEntityFlags.NO_FLAGS) // list streams on ALL containers client.listEntities("streams", StreamBaseClient.ListEntityFlags.ALL_CONTAINERS)Note: if the container you are connected to does not exist when issuing this request, and this call is made without the
StreamBaseClient.ListEntityFlags.ALL_CONTAINERSflag, the request will fail.- Parameters:
entityPath- the entity type to do the lookup. Use container.entity-type to resolve across containersflags- a combination of flags fromStreamBaseClient.ListEntityFlagsstrategy- the strategy to use for capture fields- Returns:
- an array of entity names for the given entity type
- Throws:
StreamBaseException- thrown on network or other errors- Since:
- 7.2.6
- See Also:
EntityType,StreamBaseClient.ListEntityFlags
-
listEntities
public String[] listEntities(String entityPath, int flags) throws StreamBaseException
Return an array of entity names for the given entity path. The entityPath can be either a simple entity type: "streams" or a path that includes a container such as: "mycontainer.streams". Valid entity types are from theEntityTypeclassExamples are as follows:
// list streams on container specified in StreamBaseURI given to StreamBaseClient client.listEntities("streams", StreamBaseClient.ListEntityFlags.NO_FLAGS) // list streams on container "other" client.listEntities("other.streams", StreamBaseClient.ListEntityFlags.NO_FLAGS) // list streams on ALL containers client.listEntities("streams", StreamBaseClient.ListEntityFlags.ALL_CONTAINERS)Note: if the container you are connected to does not exist when issuing this request, and this call is made without the
StreamBaseClient.ListEntityFlags.ALL_CONTAINERSflag, the request will fail.- Parameters:
entityPath- the entity type to do the lookup. Use container.entity-type to resolve across containersflags- a combination of flags fromStreamBaseClient.ListEntityFlags- Returns:
- an array of entity names for the given entity type
- Throws:
StreamBaseException- thrown on network or other errors- See Also:
EntityType,StreamBaseClient.ListEntityFlags
-
subscribe
public StreamProperties subscribe(String streamname) throws StreamBaseException
Subscribe to a stream- Parameters:
streamname- the stream to subscribe to- Returns:
- the stream properties
- Throws:
StreamBaseException- thrown on error
-
subscribe
public StreamProperties subscribe(String streamName, CaptureTransformStrategy strategy) throws StreamBaseException
Subscribe to a stream- Parameters:
streamName- the name of a stream, that may be fully qualified (for example,mycontainer.MyInputSchema). When unqualified, the container from the URI the connection was established with is used, otherwiseStreamBaseURI.DEFAULT_CONTAINERis used.strategy- the capture transform strategy- Returns:
- the stream properties
- Throws:
StreamBaseException- thrown on error- Since:
- 7.2.6
-
subscribe
public StreamProperties subscribe(StreamProperties props) throws StreamBaseException
Subscribe to a stream- Parameters:
props- the stream to subscribe to- Returns:
- the stream properties
- Throws:
StreamBaseException- thrown on error
-
subscribe
public StreamProperties subscribe(String streamname, String logicalstream, String predicate) throws StreamBaseException
Subscribe to a stream with a predicate. The stream name of dequeued tuples is logicalstream. When unsubscribing, use logicalstream.- Parameters:
streamname- the stream to subscribe tologicalstream- the name of the logical stream to associate with this predicate (if empty or null, defaults to streamname)predicate- a predicate to apply to subset the stream- Returns:
- the stream properties
- Throws:
StreamBaseException- thrown on error, including empty or null streamname or predicate
-
subscribe
public StreamProperties subscribe(String streamName, CaptureTransformStrategy strategy, String logicalstream, String predicate) throws StreamBaseException
Subscribe to a stream with a predicate. The stream name of dequeued tuples is logicalstream. When unsubscribing, use logicalstream.- Parameters:
streamName- the name of a stream, that may be fully qualified (for example,mycontainer.MyInputSchema). When unqualified, the container from the URI the connection was established with is used, otherwiseStreamBaseURI.DEFAULT_CONTAINERis used.strategy- the CaptureTransformStrategy to use if there are capture fields in the streamlogicalstream- the name of the logical stream to associate with this predicate (if empty or null, defaults to streamname)predicate- a predicate to apply to subset the stream- Returns:
- Stream properties
- Throws:
StreamBaseException- thrown on error, including empty or null streamname or predicate- Since:
- 7.2.6
-
subscribe
public StreamProperties subscribe(StreamProperties props, String logicalstream, String predicate) throws StreamBaseException
Subscribe to a stream with a predicate. The stream name of dequeued tuples is logicalstream. When unsubscribing, use logicalstream.- Parameters:
props- the stream to subscribe tologicalstream- the name of the logical stream to associate with this predicate (if empty or null, defaults to streamname)predicate- a predicate to apply to subset the stream- Returns:
- stream properties
- Throws:
StreamBaseException- thrown on error, including empty or null streamname or predicate
-
resubscribe
public StreamProperties resubscribe(String streamname, String logicalstream, String predicate) throws StreamBaseException
Resubscribe to a stream with a predicate. Allows the client to change the filtered subscribe predicate atomically so that currently buffered data is not lost (as would happen if you unsubscribed, then subscribed again with a different predicate).- Parameters:
streamname- the stream to subscribe tologicalstream- the name of the logical stream to associate with this predicatepredicate- a predicate to apply to subset the stream- Returns:
- stream properties
- Throws:
StreamBaseException- thrown on error
-
resubscribe
public StreamProperties resubscribe(StreamProperties props, String logicalstream, String predicate) throws StreamBaseException
Resubscribe to a stream with a predicate. Allows the client to change the filtered subscribe predicate atomically so that currently buffered data is not lost (as would happen if you unsubscribed, then subscribed again with a different predicate).- Parameters:
props- the stream to subscribe tologicalstream- the name of the logical stream to associate with this predicatepredicate- a predicate to apply to subset the stream- Returns:
- stream properties
- Throws:
StreamBaseException- thrown on error
-
typecheck
public StreamProperties[] typecheck(String application) throws StreamBaseException
Typecheck (validate) the given StreamBase Application. Return a list of StreamProperties for that Application- Parameters:
application- contents of an application. Text sbapp or ssql.- Returns:
- a list of StreamProperties for the StreamBase application
- Throws:
StreamBaseException- on network or typecheck error
-
typecheck
public StreamProperties[] typecheck(String application, boolean full) throws StreamBaseException
Typecheck (validate) the given StreamBase Application. Return a list of StreamProperties for that Application- Parameters:
application- contents of an application. Text sbapp or ssql.full- do a full typecheck- Returns:
- a list of StreamProperties for the StreamBase application
- Throws:
StreamBaseException- on network or typecheck error
-
unsubscribe
public void unsubscribe(String logicalStreamName) throws StreamBaseException
Unsubscribe from the given stream name. Note: Any tuples that are in-flight during an unsubscribe request will be dequeued until the stream is fully drained.- Parameters:
logicalStreamName- the name of the stream to unsubscribe from, which is logical streamname on filtered subscribe- Throws:
StreamBaseException- thrown on network or other errors
-
unsubscribe
public void unsubscribe(StreamProperties logicalProps) throws StreamBaseException
Unsubscribe from the given stream name. Note: Any tuples that are in-flight during an unsubscribe request will be dequeued until the stream is fully drained.- Parameters:
logicalProps- the StreamProperties for this logical subscription- Throws:
StreamBaseException- thrown on network or other errors
-
unsubscribeInternal
protected void unsubscribeInternal(StreamProperties logicalProps) throws StreamBaseException
Un-subscribe from stream- Parameters:
logicalProps- Properties- Throws:
StreamBaseException- Error un-subscribing
-
getConnectionID
public byte[] getConnectionID()
Return the Connection ID for this Client Connection. Only Valid once an enqueue/dequeue has been attempted.- Returns:
- binary connection id or null if connection hasn't been established
-
getSubscribedStreamNames
public Set<String> getSubscribedStreamNames()
Returns a Set of names of the Streams this client is currently subscribed to. This list is cached locally.- Returns:
- Set of Stream names as Strings
-
isSubscribed
public boolean isSubscribed(StreamProperties stream)
Return status if we are subscribed to the given stream- Parameters:
stream- the stream we want to check- Returns:
- status if we are subscribed to the given stream
- Since:
- 6.4
-
checkValidStreamname
protected static void checkValidStreamname(String streamname) throws StreamBaseException
Validate stream name- Parameters:
streamname- Stream name- Throws:
StreamBaseException- Invalid stream name
-
getDynamicVariable
public Object getDynamicVariable(String dynamicVariablePath) throws StreamBaseException
Get the given dynamic variable- Parameters:
dynamicVariablePath- the path to the dynamic variable, expressed as the path to the module containing the dynamic variable, and then a dot, and then the name of the dynamic variable.- Returns:
- the value of the dynamic variable, with the same Java type as would be returned by
Tuple.getField(String) - Throws:
StreamBaseException- if the dynamic variable path does not exist or an error occurs while communicating with the server- Since:
- 7.0
-
getDynamicVariables
public Tuple getDynamicVariables(String modulePath) throws StreamBaseException
Get a Tuple of all the dynamic variables on the given module- Parameters:
modulePath- the module to get the dynamic variables of- Returns:
- a Tuple of all the dynamic variables in the given module. The fields in the tuple are the names of the dynamic variables, the values are the current values of the dynamic variables.
- Throws:
StreamBaseException- if the module does not exist, or an error occurs while communicating with the server- Since:
- 7.0
-
setDynamicVariable
public void setDynamicVariable(String dynvarPath, Object value) throws StreamBaseException
Set the given dynamic variable to a new value- Parameters:
dynvarPath- the path to the dynamic variable to set. This consists of the dotted path to the module that contains the dynamic variable, followed by a dot, followed by the name of the dynamic variable.value- the value to set the dynamic variable to. It should be the same type thatgetDynamicVariable(String)would return for this dynamic variable.- Throws:
StreamBaseException- if the dynamic variable does not exist, or the value is not appropriate for setting the dynamic variable- Since:
- 7.0
-
getTupleEnqueueCount
public long getTupleEnqueueCount()
Returns the number of tuples this client has actually enqueued to the server. Note that this number will not include any tuples that have been buffered but have not actually been enqueued to the server.- Returns:
- number of tuples enqueued
-
getTupleDequeueCount
public long getTupleDequeueCount()
Returns the number of tuples this client has dequeued from the server. This number does not include tuples that may be dequeued as part of system services such as heartbeating. This number does however include tuples that have been dequeued but have been intercepted by the Interceptor.- Returns:
- number of tuples dequeued
-
getEnqueueBufferSize
public int getEnqueueBufferSize()
Return the number of tuples in the enqueue buffer- Returns:
- number of tuples in the enqueue buffer
-
readTable
public List<Tuple> readTable(String tablePath, int rowLimit) throws StreamBaseException
Return rows from a Query Table or Materialized Window. No guarantees are made regarding the order of rows returned.- Parameters:
tablePath- Path to the table. A fully qualified path is a dot-separated string optionally starting with a container name (when omitted, the container specified by this client's URI is used), followed by zero or more module reference names, and finally the table or window name. For example,default.ModuleRef1.DataTableis a valid fully qualified path, wheredefault.may be omitted when this client is connected to the default container.rowLimit- Limit on number of rows to return, or -1 for all rows.- Returns:
- A list of rows from the table.
- Throws:
StreamBaseException- If the connection is not valid or the server cannot be contacted, or the table does not exist, or the predicate is faulty.- Since:
- 7.2 Initial version, 10.2 Executes a cluster wide-query on partitioned transasctional memory tables
-
readTable
public List<Tuple> readTable(String tablePath, int rowLimit, String predicate) throws StreamBaseException
Return rows from a Query Table or Materialized Window, applying an optional predicate to decide which rows are returned. No guarantees are made regarding the order of rows returned.- Parameters:
tablePath- Path to the table. A fully qualified path is a dot-separated string optionally starting with a container name (when omitted, the container specified by this client's URI is used), followed by zero or more module reference names, and finally the table or window name. For example,default.ModuleRef1.DataTableis a valid fully qualified path, wheredefault.may be omitted when this client is connected to the default container.rowLimit- Limit on number of rows to return, or -1 for all rows.predicate- A predicate to apply to the rows to select those for retrieval. A null predicate returns all rows.- Returns:
- A list of rows from the table.
- Throws:
StreamBaseException- If the connection is not valid or the server cannot be contacted, or the table does not exist, or the predicate is faulty.- Since:
- 7.2 Initial version, 10.2 Executes a cluster wide-query on partitioned transasctional memory tables
-
addConnectionStatusCallback
public void addConnectionStatusCallback(ConnectionStatusCallback callback)
Track changes to the connection state. When a state change occurs, such as the client connecting or disconnecting, call the stateChanged method.- Parameters:
callback- a class that implements the ConnectionStatusCallback interface
-
removeConnectionStatusCallback
public void removeConnectionStatusCallback(ConnectionStatusCallback callback)
Stop tracking changes to the connection state.- Parameters:
callback- an instance of ConnectionStatusCallback
-
setConnectionStatus
protected void setConnectionStatus(ConnectionStatus status, String additionalInfo)
Set connection status- Parameters:
status- New statusadditionalInfo- Additional information
-
getConnectionStatus
public ConnectionStatus getConnectionStatus()
Return the current connection status of this StreamBaseClient.- Returns:
- the current connection status (CREATED, CONNECTED, DISCONNECTED)
-
getConnectionError
public String getConnectionError()
If the StreamBaseClient disconnected due to an internal error, return a message corresponding to the error, otherwise return null.- Returns:
- the error message that caused the client to disconnect, null if not applicable
-
haModeOn
protected boolean haModeOn()
is HA mode on- Returns:
- if HA mode is on
-
getSettings
public ClientSettings getSettings()
Return the settings for this client- Returns:
- settings for this client
-
status
public String[] status() throws StreamBaseException
Return the status of the StreamBase Server- Returns:
- the status
- Throws:
StreamBaseException- thrown on network and other errors
-
status
public String[] status(boolean verbose) throws StreamBaseException
Return the status of the StreamBase Server- Parameters:
verbose- return a verbose status- Returns:
- the status
- Throws:
StreamBaseException- thrown on network and other errors
-
operatorStatus
public String[] operatorStatus(String containerName) throws StreamBaseException
Return the status of all the operators in the specified container- Parameters:
containerName- the name of the container- Returns:
- an array of strings of the form "operatorname=status"
- Throws:
StreamBaseException- error getting status
-
getURI
public StreamBaseURI getURI()
Return the URI used by this Client. In HA mode this just returns the 1st URI for the client- Returns:
- the uri for this client
-
getURIs
public List<StreamBaseURI> getURIs()
get all of the URI's for this client- Returns:
- all of the URI's for this client
-
-