Esempio n. 1
0
    class Type(Enum):
        CURRENT = SiddhiLoader._loadType(
            "org.wso2.siddhi.pythonapi.proxy.core.event.complex_event.TypeProxy"
        )().CURRENT(),
        EXPIRED = SiddhiLoader._loadType(
            "org.wso2.siddhi.pythonapi.proxy.core.event.complex_event.TypeProxy"
        )().EXPIRED(),
        TIMER = SiddhiLoader._loadType(
            "org.wso2.siddhi.pythonapi.proxy.core.event.complex_event.TypeProxy"
        )().TIMER(),
        RESET = SiddhiLoader._loadType(
            "org.wso2.siddhi.pythonapi.proxy.core.event.complex_event.TypeProxy"
        )().RESET()

        @classmethod
        def _map_value(cls, type_proxy):
            type_value = None
            if type_proxy.isValueCurrent():
                type_value = ComplexEvent.Type.CURRENT
            elif type_proxy.isValueExpired():
                type_value = ComplexEvent.Type.EXPIRED
            elif type_proxy.isValueTimer():
                type_value = ComplexEvent.Type.TIMER
            elif type_proxy.isValueReset():
                type_value = ComplexEvent.Type.RESET
            else:
                raise TypeError("Unknown Complex Event Type")
            return ComplexEvent.Type(type_value)
Esempio n. 2
0
 def getOutputData(self):
     complex_event_static_proxy = SiddhiLoader._loadType(
         "org.wso2.siddhi.pythonapi.proxy.core.event.complex_event.ComplexEventProxy"
     )()
     output_data = unwrapData(
         complex_event_static_proxy.getOutputData(
             self._complex_event_proxy))
     return output_data
Esempio n. 3
0
    class QueryTerminal(Enum):
        '''
        SiddhiDebugger allows to add breakpoints at the beginning and the end of a query.
        '''
        IN = SiddhiLoader._loadType(
            "org.wso2.siddhi.pythonapi.proxy.core.debugger.siddhi_debugger.QueryTerminalProxy")().IN()
        OUT = SiddhiLoader._loadType(
            "org.wso2.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)
Esempio 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)
Esempio n. 5
0
def wrapDataItem(d):
    '''
    Wraps a data item (int, long, string or float) , making it suitable to be transfered to Java Proxy
    :param d: 
    :return: 
    '''
    wrapped_data_proxy = SiddhiLoader._loadType(
        "org.wso2.siddhi.pythonapi.DataWrapProxy")
    wrapped_data = None
    if d is None:
        # Constructor for null type
        wrapped_data = wrapped_data_proxy(0, False, True)
    elif type(d) is LongType:
        # Consutrctor for Long Type
        wrapped_data = wrapped_data_proxy(d, True)
    elif type(d) is DoubleType:
        wrapped_data = wrapped_data_proxy(d, False, False, True)
    else:
        wrapped_data = wrapped_data_proxy(d)
    return wrapped_data
Esempio n. 6
0
# "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 PySiddhi4 import SiddhiLoader
from PySiddhi4.core.event.Event import Event

from future.utils import with_metaclass

_query_callback_proxy = SiddhiLoader._loadType(
    "org.wso2.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 org.wso2.siddhi.core.query.output.callback.QueryCallback
    '''
    def __init__(self):
        self._query_callback_proxy_inst = _query_callback_proxy()
        query_callback_self = self
Esempio n. 7
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 PySiddhi4 import SiddhiLoader

_event_printer_proxy = SiddhiLoader._loadType(
    "org.wso2.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]
Esempio 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 PySiddhi4 import SiddhiLoader

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

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


class Event(object):
    '''
    Wrapper on @org.wso2.siddhi.core.event.Event
    '''
    @classmethod
    def _fromEventProxy(cls, event_proxy):
        '''
        Internal Constructor to wrap around JAVA class Event
        :param event_proxy:
        :return:
Esempio n. 9
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 PySiddhi4 import SiddhiLoader

_siddhi_debugger_callback_proxy = SiddhiLoader._loadType(
    "org.wso2.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):
Esempio n. 10
0
# specific language governing permissions and limitations
# under the License.

from multiprocessing import RLock

import logging

from abc import ABCMeta, abstractmethod

from PySiddhi4 import SiddhiLoader
from PySiddhi4.core.event.Event import Event

from future.utils import with_metaclass

_stream_callback_proxy = SiddhiLoader._loadType(
    "org.wso2.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
Esempio n. 11
0
 def setOutputData(self, datum, index):
     complex_event_static_proxy = SiddhiLoader._loadType(
         "org.wso2.siddhi.pythonapi.proxy.core.event.complex_event.ComplexEventProxy"
     )()
     complex_event_static_proxy.setOutputData(self._complex_event_proxy,
                                              wrapData(datum), index)
Esempio n. 12
0
 def getType(self):
     raw_type_proxy = self._complex_event_proxy.getType()
     type_proxy = SiddhiLoader._loadType(
         "org.wso2.siddhi.pythonapi.proxy.core.event.complex_event.TypeProxy"
     )(raw_type_proxy)
     return ComplexEvent.Type._map_value(type_proxy)
Esempio n. 13
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 PySiddhi4 import SiddhiLoader
from PySiddhi4.DataTypes.DataWrapper import wrapData

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


class InputHandler(object):
    '''
    Handles input to SiddhiAppRuntime.
    Wrapper on org.wso2.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