Class Stream


  • public class Stream
    extends java.lang.Object
    Stream is the entry point for SwiftMQ Streams.

    It is passed as a global variable "stream" to Stream Scripts and is used to create and access Stream resources such as Memories, Timers, Inputs etc.

    Author:
    IIT Software GmbH, Muenster/Germany, (c) 2016, All Rights Reserved
    • Field Detail

      • closed

        public boolean closed
    • Constructor Detail

      • Stream

        public Stream​(StreamContext ctx,
                      java.lang.String domainName,
                      java.lang.String packageName,
                      java.lang.String name,
                      int restartCount)
        Internal use only
    • Method Detail

      • getStreamCtx

        public StreamContext getStreamCtx()
        Internal use
        Returns:
        stream context
      • routerName

        public java.lang.String routerName()
        Returns the name of the local Router.
        Returns:
        routerName
      • domainName

        public java.lang.String domainName()
        Returns the Domain Name of this Stream.
        Returns:
        domain name
      • packageName

        public java.lang.String packageName()
        Returns the Package Name of this Stream
        Returns:
        package name
      • name

        public java.lang.String name()
        Returns the name of this stream
        Returns:
        name
      • fullyQualifiedName

        public java.lang.String fullyQualifiedName()
        Returns the fully qualified Stream name: domain.package.name
        Returns:
        fully qualified name
      • restartCount

        public int restartCount()
        Returns the restart count of this stream
        Returns:
        restart count
      • log

        public Log log()
        Returns the stream's Log
        Returns:
        Log
      • cli

        public CLI cli()
        Returns the stream's CLI
        Returns:
        CLI
      • getWorkingDirectory

        public java.lang.String getWorkingDirectory()
        Returns the working directory of the router
        Returns:
      • stateMemory

        public Memory stateMemory()
        Returns the Stream's State Memory that is used by MemoryGroups to store their associated Memories.
        Returns:
        stateMemory
      • addMemory

        public Memory addMemory​(java.lang.String name,
                                Memory memory)
        Internal use only
      • addMemoryGroup

        public MemoryGroup addMemoryGroup​(java.lang.String name,
                                          MemoryGroup memoryGroup)
        Internal use only
      • removeMemory

        public void removeMemory​(Memory memory)
        Internal use only
      • removeMemoryGroup

        public void removeMemoryGroup​(MemoryGroup memoryGroup)
        Internal use only
      • addTimer

        public Timer addTimer​(java.lang.String name,
                              Timer timer)
        Internal use only
      • removeTimer

        public Stream removeTimer​(Timer timer)
        Internal use only
      • addInput

        public Input addInput​(java.lang.String name,
                              Input input)
                       throws java.lang.Exception
        Internal use only
        Throws:
        java.lang.Exception
      • removeInput

        public Stream removeInput​(Input input)
        Internal use only
      • addOutput

        public Output addOutput​(java.lang.String name,
                                Output output)
        Internal use only
      • removeOutput

        public Stream removeOutput​(java.lang.String name)
        Internal use only
      • addMailServer

        public MailServer addMailServer​(java.lang.String name,
                                        MailServer mailServer)
        Internal use only
      • removeMailServer

        public Stream removeMailServer​(java.lang.String name)
        Internal use only
      • addJDBCLookup

        public JDBCLookup addJDBCLookup​(java.lang.String name,
                                        JDBCLookup jdbcLookup)
        Internal use only
      • removeJDBCLookup

        public Stream removeJDBCLookup​(java.lang.String name)
        Internal use only
      • addTempQueue

        public TempQueue addTempQueue​(java.lang.String name,
                                      TempQueue tempQueue)
        Internal use only
      • removeTempQueue

        public Stream removeTempQueue​(TempQueue tempQueue)
        Internal use only
      • getTimers

        public Timer[] getTimers()
        Internal use only
      • getInputs

        public Input[] getInputs()
        Internal use only
      • getOutputs

        public Output[] getOutputs()
        Internal use only
      • getMemories

        public Memory[] getMemories()
        Internal use only
      • deferredClose

        public void deferredClose()
        Internal use only
      • getMemoryGroups

        public MemoryGroup[] getMemoryGroups()
        Internal use only
      • getMailservers

        public MailServer[] getMailservers()
        Internal use only
      • getJDBCLookups

        public JDBCLookup[] getJDBCLookups()
        Internal use only
      • getTempQueues

        public TempQueue[] getTempQueues()
        Internal use only
      • create

        public StreamBuilder create()
        Returns a stream builder to create stream resources
        Returns:
        stream builder
      • input

        public Input input​(java.lang.String name)
        Returns the Input with the given name.
        Parameters:
        name - Name of the Input
        Returns:
        Input
      • input

        public Input input​(TempQueue tempQueue)
        Returns the Input for this TempQueue.
        Parameters:
        tempQueue - temp queue
        Returns:
        Input
      • output

        public Output output​(java.lang.String name)
        Returns the Output with the given name.
        Parameters:
        name - Name of the Output
        Returns:
        Output
      • jdbcLookup

        public JDBCLookup jdbcLookup​(java.lang.String name)
        Returns the JDBCLookup with the given name.
        Parameters:
        name - Name of the JDBCLookup
        Returns:
        JDBCLookup
      • mailserver

        public MailServer mailserver​(java.lang.String name)
        Returns the MailServer with the given name.
        Parameters:
        name - Name of the MailServer
        Returns:
        MailServer
      • timer

        public Timer timer​(java.lang.String name)
        Returns the Timer with the given name.
        Parameters:
        name - Name of the Timer
        Returns:
        Timer
      • memory

        public Memory memory​(java.lang.String name)
        Returns the Memory with the given name.
        Parameters:
        name - Name of the Memory
        Returns:
        Memory
      • memoryGroup

        public MemoryGroup memoryGroup​(java.lang.String name)
        Returns the MemoryGroup with the given name.
        Parameters:
        name - Name of the MemoryGroup
        Returns:
        MemoryGroup
      • tempQueue

        public TempQueue tempQueue​(java.lang.String name)
        Returns the TempQueue with the given name.
        Parameters:
        name - Name of the TempQueue
        Returns:
        TempQueue
      • queue

        public QueueImpl queue​(java.lang.String name)
        Factory method to return a new QueueImpl (address)
        Parameters:
        name - queue name
        Returns:
        QueueImpl
      • topic

        public TopicImpl topic​(java.lang.String name)
        Factory method to return a new TopicImpl (address)
        Parameters:
        name - topic name
        Returns:
        TopicImpl
      • lookupJNDI

        public javax.jms.Destination lookupJNDI​(java.lang.String name)
                                         throws java.lang.Exception
        Returns a Destination registered in JNDI under this name.
        Parameters:
        name - Name at which the Destination is registered
        Returns:
        Destination
        Throws:
        java.lang.Exception
      • purgeOutputs

        public Stream purgeOutputs()
        Closes all Outputs that were not used between the last and this call to this method.
        Returns:
        this
      • current

        public Stream current​(Message current)
        Sets/overwrites the currently processed Message.
        Parameters:
        current - current Message
        Returns:
        Stream
      • current

        public Message current()
        Returns the currently processed Message. This is automatically set from the stream processor before calling onMessage and set to null thereafter.
        Returns:
        current Message
      • onMessage

        public Stream onMessage​(java.lang.Runnable runnable)
        Sets the onMessage callback.
        Parameters:
        runnable - callback
        Returns:
        Stream
      • onException

        public Stream onException​(ExceptionCallback runnable)
        Sets the onException callback.
        Parameters:
        runnable - callback
        Returns:
      • onStart

        public Stream onStart​(java.lang.Runnable runnable)
        Sets the onStart callback.
        Parameters:
        runnable - callback
        Returns:
      • onStop

        public Stream onStop​(java.lang.Runnable runnable)
        Sets the onStop callback.
        Parameters:
        runnable - callback
        Returns:
      • executeCallback

        public Stream executeCallback​(FunctionCallback functionCallback,
                                      java.lang.Object context)
        Executes a function callback in the Stream's event queue. This is one method to execute asynchronous calls from libraries. This does not work in GraalVM. Please use stream.async(...)
        Parameters:
        functionCallback - callback
        context - optional context
        Returns:
        this
      • async

        public java.lang.Object async​(java.lang.String interfaceClassName,
                                      java.lang.Object callback)
                               throws java.lang.Exception
        Wraps an async callback with a proxy that implements the interface given by the "interfaceClassName" and runs the callback on the Stream's event queue. This works on GraalVM and Nashorn.
        Parameters:
        interfaceClassName - Fully qualified class name of the interface to implement
        callback - Callback
        Returns:
        proxy object
        Throws:
        java.lang.Exception
      • lastException

        public java.lang.String lastException()
        Returns the last exception occurred on the stream
        Returns:
        last exception
      • lastStackTrace

        public java.lang.String lastStackTrace()
        Returns the formatted stack trace of the last exception occurred on the stream
        Returns:
        stack trace
      • executeOnExceptionCallback

        public void executeOnExceptionCallback()
        Internal use only
      • executeOnMessageCallback

        public void executeOnMessageCallback()
                                      throws java.lang.Exception
        Internal use only
        Throws:
        java.lang.Exception
      • executeOnStartCallback

        public void executeOnStartCallback()
        Internal use only
      • executeOnStopCallback

        public void executeOnStopCallback()
        Internal use only
      • collect

        public void collect​(long interval)
        Internal use only
      • start

        public void start()
                   throws java.lang.Exception
        Internal use only
        Throws:
        java.lang.Exception
      • close

        public void close()
        Internal use only
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object