Exemplo n.º 1
0
 def __init__(self):
     '''
     ''Initialize a new SiddhiManager
     '''
     SiddhiLoader.loadLibrary()
     self._siddhi_manager_proxy = SiddhiLoader.siddhi_api_core_inst.initSiddhiManager(
     )
Exemplo n.º 2
0
            def pollLoop():
                event_polling_started = False

                with self.pollLock:
                    event_polling_started = self.event_polling_started

                while event_polling_started:
                    with self.pollLock:
                        event = self.event_queue.getQueuedEvent()
                        if event is not None:
                            if event.isDebugEvent():
                                debug_callback = self.debugCallback
                                if debug_callback is not None:
                                    complexEvent = event.getComplexEvent(0)
                                    queryName = event.getString(1)
                                    queryTerminal = event.getQueryTerminal(2)
                                    debugger = event.getSiddhiDebugger(3)

                                    complexEvent = ComplexEvent._fromComplexEventProxy(complexEvent)
                                    queryTerminal = SiddhiDebugger.QueryTerminal._map_value(queryTerminal)
                                    debugger = SiddhiDebugger._fromSiddhiDebuggerProxy(debugger)

                                    debug_callback.debugEvent(complexEvent, queryName, queryTerminal, debugger)
                                elif event.isGCEvent():
                                    self.debugCallback = None  # Release reference held with callback since it has been
                                    # destroyed from Java Side

                    sleep(0.005)  # NOTE: Removing this sleep causes changing of Debug Callback to fail
                    # TODO: Investigate why removal of above sleep causes condition in above note

                # Requirement of Pyjnius to call detach before destruction of a thread
                SiddhiLoader._detachThread()
Exemplo n.º 3
0
    class QueryTerminal(Enum):
        '''
        SiddhiDebugger allows to add breakpoints at the beginning and the end of a query.
        '''
        IN = SiddhiLoader._loadType(
            "io.siddhi.pythonapi.proxy.core.debugger.siddhi_debugger.QueryTerminalProxy")().IN()
        OUT = SiddhiLoader._loadType(
            "io.siddhi.pythonapi.proxy.core.debugger.siddhi_debugger.QueryTerminalProxy")().OUT()

        @classmethod
        def _map_value(cls, queryTerminalProxy):
            qt_value = None
            if queryTerminalProxy.isValueOut():
                qt_value = SiddhiDebugger.QueryTerminal.OUT
            elif queryTerminalProxy.isValueIn():
                qt_value = SiddhiDebugger.QueryTerminal.IN
            else:
                raise TypeError("Unknown QueryTerminal Value")
            return SiddhiDebugger.QueryTerminal(qt_value)
Exemplo n.º 4
0
 def setExtension(self, name, clazz):
     '''
     Loads an extension into Siddhi Manager. The Extension Path must be already added via 
     SiddhiLoader.addExtensionPath.
     :param name: Name of extension
     :param clazz: Fully qualified class name of extension
     :return: 
     '''
     if isinstance(clazz, str):
         self._siddhi_manager_proxy.setExtension(
             name, SiddhiLoader._loadType(clazz))
     else:
         self._siddhi_manager_proxy.setExtension(name, clazz)
Exemplo n.º 5
0
# specific language governing permissions and limitations
# under the License.

from multiprocessing import RLock

import logging

from abc import ABCMeta, abstractmethod

from PySiddhi import SiddhiLoader
from PySiddhi.core.event.Event import Event

from future.utils import with_metaclass

_stream_callback_proxy = SiddhiLoader._loadType(
    "io.siddhi.pythonapi.proxy.core.stream.output.callback.stream_callback.StreamCallbackProxy"
)

_lock = RLock()

_created_instances = [
]  # Hold reference to prevent python from GC callback before java does


class StreamCallback(with_metaclass(ABCMeta, object)):
    '''
    StreamCallback is used to receive events from StreamJunction
    This class should be extended if one intends to get events from a Siddhi Stream.
    '''

    # __metaclass__ = ABCMeta
Exemplo n.º 6
0
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import logging

from abc import ABCMeta, abstractmethod

from PySiddhi import SiddhiLoader
from PySiddhi.core.event.Event import Event

from future.utils import with_metaclass

_query_callback_proxy = SiddhiLoader._loadType(
    "io.siddhi.pythonapi.proxy.core.query.output.callback.query_callback.QueryCallbackProxy")

_created_instances = []  # Hold references to prevent python from GCing Callbacks until Java does


class QueryCallback(with_metaclass(ABCMeta, object)):
    '''
    Callback to receive events from SiddhiAppRuntime. Should be extended by child class.
    Wrapper on io.siddhi.core.query.output.callback.QueryCallback
    '''

    def __init__(self):
        self._query_callback_proxy_inst = _query_callback_proxy()
        query_callback_self = self

        class ReceiveCallback(SiddhiLoader._PythonJavaClass):
Exemplo n.º 7
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from PySiddhi import SiddhiLoader

from PySiddhi.DataTypes import DataWrapper
from PySiddhi.core.event import ComplexEvent

_event_class = SiddhiLoader._loadType("io.siddhi.core.event.Event")
_event_proxy_class = SiddhiLoader._loadType(
    "io.siddhi.pythonapi.proxy.core.event.event.EventProxy")
_event_proxy_class_inst = _event_proxy_class()


class Event(object):
    '''
    Wrapper on @io.siddhi.core.event.Event
    '''
    @classmethod
    def _fromEventProxy(cls, event_proxy):
        '''
        Internal Constructor to wrap around JAVA class Event
        :param event_proxy:
        :return:
Exemplo n.º 8
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.


from abc import ABCMeta, abstractmethod
from future.utils import with_metaclass
from PySiddhi import SiddhiLoader

_siddhi_debugger_callback_proxy = SiddhiLoader._loadType(
    "io.siddhi.pythonapi.proxy.core.debugger.siddhi_debugger_callback.SiddhiDebuggerCallbackProxy")


class SiddhiDebuggerCallback(with_metaclass(ABCMeta, object)):
    '''
    Callback to get notification about the events passing through the break points.
    Should be extended by subclass.
    '''

    def __init__(self):
        _siddhi_debugger_callback_self = self
        self._siddhi_debugger_callback_proxy_inst = _siddhi_debugger_callback_proxy()

    @abstractmethod
    def debugEvent(self, complexEvent, queryName, queryTerminal, debugger):
        '''
Exemplo n.º 9
0
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from PySiddhi import SiddhiLoader
from PySiddhi.DataTypes.DataWrapper import wrapData

input_handler_proxy = SiddhiLoader._loadType(
    "io.siddhi.pythonapi.proxy.core.stream.input.input_handler.InputHandlerProxy"
)


class InputHandler(object):
    '''
    Handles input to SiddhiAppRuntime.
    Wrapper on io.siddhi.core.stream.input.InputHandler
    '''
    def __init__(self):
        raise NotImplementedError(
            "Initialize InputHandler using SiddhiAppRuntime")

    def __new__(cls):
        bare_instance = object.__new__(cls)
        bare_instance.input_handler_proxy = None
Exemplo n.º 10
0
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from PySiddhi import SiddhiLoader

_event_printer_proxy = SiddhiLoader._loadType(
    "io.siddhi.pythonapi.proxy.core.util.EventPrinterProxy")


def PrintEvent(timestamp, inEvents, outEvents):
    '''
    Prints Stream Event to Log
    :param timestamp:
    :param inEvents:
    :param outEvents:
    :return:
    '''
    if inEvents is not None:
        inEvents = [event._event_proxy for event in inEvents]

    if outEvents is not None:
        outEvents = [event._event_proxy for event in outEvents]