Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first commit

  • Loading branch information...
commit a6f37ca9dc540253d4ea2acc9a6f06aca1f96ade 0 parents
johndemic johndemic authored
56 LICENSE.md
Source Rendered
... ... @@ -0,0 +1,56 @@
  1 +Apache License
  2 +==============
  3 +
  4 +Version 2.0, January 2004
  5 +
  6 +http://www.apache.org/licenses/
  7 +
  8 +*TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION*
  9 +
  10 +1. Definitions.
  11 +
  12 +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
  13 +
  14 +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
  15 +
  16 +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
  17 +
  18 +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
  19 +
  20 +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
  21 +
  22 +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
  23 +
  24 +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
  25 +
  26 +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
  27 +
  28 +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
  29 +
  30 +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
  31 +
  32 +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
  33 +
  34 +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
  35 +
  36 +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
  37 +
  38 +You must give any other recipients of the Work or Derivative Works a copy of this License; and
  39 +
  40 +You must cause any modified files to carry prominent notices stating that You changed the files; and
  41 +
  42 +You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
  43 +
  44 +If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
  45 +
  46 +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
  47 +
  48 +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
  49 +
  50 +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
  51 +
  52 +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
  53 +
  54 +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
  55 +
  56 +END OF TERMS AND CONDITIONS
52 README.md
Source Rendered
... ... @@ -0,0 +1,52 @@
  1 +
  2 +WELCOME
  3 +=======
  4 +Congratulations you have just created a new Mule Cloud connector!
  5 +
  6 +Now you need to make sure that you update you pom.xml to use version
  7 +${muleVersion} of Mule. This will ensure you are compiling against the correct
  8 +version of Mule and you will avoid issues arising from not being about to find
  9 +configuration schemas for this module.
  10 +
  11 +This wizard created a number of new classes and resources useful for Mule
  12 +cloud connectors. Each of the created files contains documentation and TODO
  13 +items where necessary. Here is an overview of what was created.
  14 +
  15 +./pom.xml:
  16 +A maven project descriptor that describes how to build this module. It also
  17 +contains additional information about how to share the connector on MuleForge.
  18 +
  19 +./assembly.xml:
  20 +A maven assembly descriptor that defines how this module will be packaged
  21 +when you make a release.
  22 +
  23 +./LICENSE.txt:
  24 +The open source license text for this project.
  25 +
  26 +TESTING
  27 +=======
  28 +
  29 +This project also contains test classes that can be run as part of a test
  30 +suite.
  31 +
  32 +ADDITIONAL RESOURCES
  33 +====================
  34 +Everything you need to know about getting started with Mule can be found here:
  35 +http://www.mulesoft.org/documentation/display/MULE3INTRO/Home
  36 +
  37 +There further useful information about extending Mule here:
  38 +http://www.mulesoft.org/documentation/display/MULE3USER/Introduction+to+Extending+Mule
  39 +
  40 +For information about working with Mule inside and IDE with maven can be
  41 +found here:
  42 +http://www.mulesoft.org/documentation/display/MULE3INTRO/Setting+Up+Eclipse
  43 +
  44 +Remember if you get stuck you can try getting help on the Mule user list:
  45 +http://www.mulesoft.org/email-lists
  46 +
  47 +Also, MuleSoft, the company behind Mule, offers 24x7 support options:
  48 +http://www.mulesoft.com/enterprise-subscriptions-and-support
  49 +
  50 +Enjoy your Mule ride!
  51 +
  52 +The Mule Team
11 doc/Esper-connector.xml.sample
... ... @@ -0,0 +1,11 @@
  1 +<!-- BEGIN_INCLUDE(esper:send-event) -->
  2 + <esper:send event="#[payload:]" />
  3 +<!-- END_INCLUDE(esper:send-event) -->
  4 +
  5 +<!-- BEGIN_INCLUDE(esper:listen) -->
  6 + <esper:listen statement="select count(*) from org.mule.api.MuleMessage.win:time_batch(10, 'FORCE_UPDATE, START_EAGER') having count(*) < 5" />
  7 +<!-- END_INCLUDE(esper:listen) -->
  8 +
  9 +<!-- BEGIN_INCLUDE(esper:get-event-property) -->
  10 + <esper:get-event-property property="count(*)" />
  11 +<!-- END_INCLUDE(esper:get-event-property) -->
249 pom.xml
... ... @@ -0,0 +1,249 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4 + <modelVersion>4.0.0</modelVersion>
  5 + <groupId>org.mule.module.esper</groupId>
  6 + <artifactId>esper-connector</artifactId>
  7 + <version>1.0</version>
  8 + <packaging>mule-module</packaging>
  9 + <name>Mule Cloud Connector</name>
  10 +
  11 + <properties>
  12 + <mule.version>3.2.0</mule.version>
  13 + <mule.devkit.version>3.0.1</mule.devkit.version>
  14 + <junit.version>4.8.2</junit.version>
  15 + <mockito.version>1.8.2</mockito.version>
  16 + </properties>
  17 +
  18 + <build>
  19 + <pluginManagement>
  20 + <plugins>
  21 + <plugin>
  22 + <groupId>org.mule.tools.devkit</groupId>
  23 + <artifactId>mule-devkit-maven-plugin</artifactId>
  24 + <version>${mule.devkit.version}</version>
  25 + <extensions>true</extensions>
  26 + </plugin>
  27 + <plugin>
  28 + <groupId>org.eclipse.m2e</groupId>
  29 + <artifactId>lifecycle-mapping</artifactId>
  30 + <version>1.0.0</version>
  31 + <configuration>
  32 + <lifecycleMappingMetadata>
  33 + <pluginExecutions>
  34 + <pluginExecution>
  35 + <pluginExecutionFilter>
  36 + <groupId>org.mule.tools.devkit</groupId>
  37 + <artifactId>mule-devkit-maven-plugin</artifactId>
  38 + <versionRange>[2.0,)</versionRange>
  39 + <goals>
  40 + <goal>attach-test-resources</goal>
  41 + <goal>filter-resources</goal>
  42 + <goal>generate-sources</goal>
  43 + </goals>
  44 + </pluginExecutionFilter>
  45 + <action>
  46 + <ignore/>
  47 + </action>
  48 + </pluginExecution>
  49 + </pluginExecutions>
  50 + </lifecycleMappingMetadata>
  51 + </configuration>
  52 + </plugin>
  53 + </plugins>
  54 + </pluginManagement>
  55 + <plugins>
  56 + <plugin>
  57 + <groupId>org.apache.maven.plugins</groupId>
  58 + <artifactId>maven-compiler-plugin</artifactId>
  59 + <version>2.3.2</version>
  60 + <executions>
  61 + <execution>
  62 + <id>default-compile</id>
  63 + <configuration>
  64 + <compilerArgument>-proc:none</compilerArgument>
  65 + <source>1.6</source>
  66 + <target>1.6</target>
  67 + </configuration>
  68 + </execution>
  69 + <execution>
  70 + <id>default-testCompile</id>
  71 + <configuration>
  72 + <compilerArgument>-proc:none</compilerArgument>
  73 + <source>1.6</source>
  74 + <target>1.6</target>
  75 + </configuration>
  76 + </execution>
  77 + </executions>
  78 + </plugin>
  79 + <plugin>
  80 + <groupId>org.mule.tools.devkit</groupId>
  81 + <artifactId>mule-devkit-maven-plugin</artifactId>
  82 + <version>${mule.devkit.version}</version>
  83 + </plugin>
  84 + <plugin>
  85 + <groupId>org.apache.maven.plugins</groupId>
  86 + <artifactId>maven-source-plugin</artifactId>
  87 + <version>2.1.2</version>
  88 + <executions>
  89 + <execution>
  90 + <id>attach-sources</id>
  91 + <goals>
  92 + <goal>jar</goal>
  93 + </goals>
  94 + </execution>
  95 + </executions>
  96 + </plugin>
  97 + <plugin>
  98 + <groupId>org.apache.maven.plugins</groupId>
  99 + <artifactId>maven-javadoc-plugin</artifactId>
  100 + <version>2.8</version>
  101 + <executions>
  102 + <execution>
  103 + <id>attach-javadocs</id>
  104 + <goals>
  105 + <goal>jar</goal>
  106 + </goals>
  107 + </execution>
  108 + </executions>
  109 + <configuration>
  110 + <docletArtifact>
  111 + <groupId>org.mule.tools.devkit</groupId>
  112 + <artifactId>mule-devkit-doclet</artifactId>
  113 + <version>3.0.1</version>
  114 + </docletArtifact>
  115 + <doclet>org.mule.devkit.doclet.Doclava</doclet>
  116 + <bootclasspath>${sun.boot.class.path}</bootclasspath>
  117 + <additionalparam>
  118 + -quiet
  119 + -federate JDK http://download.oracle.com/javase/6/docs/api/index.html?
  120 + -federationxml JDK http://doclava.googlecode.com/svn/static/api/openjdk-6.xml
  121 + -hdf project.artifactId "${project.artifactId}"
  122 + -hdf project.groupId "${project.groupId}"
  123 + -hdf project.version "${project.version}"
  124 + -hdf project.name "${project.name}"
  125 + -hdf project.repo.name "${project.distributionManagement.repository.name}"
  126 + -hdf project.repo.id "${project.distributionManagement.repository.id}"
  127 + -hdf project.repo.url "${project.distributionManagement.repository.url}"
  128 + -hdf project.snapshotRepo.name "${project.distributionManagement.snapshotRepository.name}"
  129 + -hdf project.snapshotRepo.id "${project.distributionManagement.snapshotRepository.id}"
  130 + -hdf project.snapshotRepo.url "${project.distributionManagement.snapshotRepository.url}"
  131 + -d ${project.build.directory}/apidocs
  132 + </additionalparam>
  133 + <useStandardDocletOptions>false</useStandardDocletOptions>
  134 + <additionalJOption>-J-Xmx1024m</additionalJOption>
  135 + </configuration>
  136 + </plugin>
  137 + </plugins>
  138 + <resources>
  139 + <resource>
  140 + <filtering>false</filtering>
  141 + <directory>src/main/resources</directory>
  142 + </resource>
  143 + <resource>
  144 + <filtering>true</filtering>
  145 + <directory>src/test/resources</directory>
  146 + </resource>
  147 + </resources>
  148 + </build>
  149 +
  150 + <dependencies>
  151 + <dependency>
  152 + <groupId>org.mule.dsl</groupId>
  153 + <artifactId>dsl-api</artifactId>
  154 + <version>0.7</version>
  155 + <exclusions>
  156 + <exclusion>
  157 + <groupId>org.mule</groupId>
  158 + <artifactId>core</artifactId>
  159 + </exclusion>
  160 + </exclusions>
  161 + <scope>provided</scope>
  162 + </dependency>
  163 + <dependency>
  164 + <groupId>junit</groupId>
  165 + <artifactId>junit</artifactId>
  166 + <version>${junit.version}</version>
  167 + <scope>test</scope>
  168 + </dependency>
  169 + <dependency>
  170 + <groupId>org.mockito</groupId>
  171 + <artifactId>mockito-all</artifactId>
  172 + <version>${mockito.version}</version>
  173 + <scope>test</scope>
  174 + </dependency>
  175 + <dependency>
  176 + <groupId>org.mule.modules</groupId>
  177 + <artifactId>mule-module-spring-config</artifactId>
  178 + <version>${mule.version}</version>
  179 + </dependency>
  180 + <dependency>
  181 + <groupId>org.mule.modules</groupId>
  182 + <artifactId>mule-module-client</artifactId>
  183 + <version>${mule.version}</version>
  184 + <scope>test</scope>
  185 + </dependency>
  186 + <dependency>
  187 + <groupId>org.mule.tools.devkit</groupId>
  188 + <artifactId>mule-devkit-annotations</artifactId>
  189 + <version>${mule.devkit.version}</version>
  190 + </dependency>
  191 + <dependency>
  192 + <groupId>com.espertech</groupId>
  193 + <artifactId>esper</artifactId>
  194 + <version>4.4.0</version>
  195 + </dependency>
  196 + <dependency>
  197 + <groupId>org.mule.tests</groupId>
  198 + <artifactId>mule-tests-functional</artifactId>
  199 + <version>${mule.version}</version>
  200 + <scope>test</scope>
  201 + </dependency>
  202 + <dependency>
  203 + <groupId>org.mule.transports</groupId>
  204 + <artifactId>mule-transport-vm</artifactId>
  205 + <version>${mule.version}</version>
  206 + <scope>test</scope>
  207 + </dependency>
  208 + </dependencies>
  209 +
  210 + <repositories>
  211 + <repository>
  212 + <id>muleforge-releases</id>
  213 + <name>MuleForge Releases Repository</name>
  214 + <url>http://repository.mulesoft.org/releases/</url>
  215 + <layout>default</layout>
  216 + </repository>
  217 + <repository>
  218 + <id>muleforge-snapshots</id>
  219 + <name>MuleForge Snapshots Repository</name>
  220 + <url>http://repository.mulesoft.org/snapshots/</url>
  221 + <layout>default</layout>
  222 + </repository>
  223 + </repositories>
  224 +
  225 + <pluginRepositories>
  226 + <pluginRepository>
  227 + <id>muleforge-plugin-releases</id>
  228 + <name>Muleforge Release Repository</name>
  229 + <url>http://repository.mulesoft.org/releases/</url>
  230 + <releases>
  231 + <enabled>true</enabled>
  232 + </releases>
  233 + <snapshots>
  234 + <enabled>false</enabled>
  235 + </snapshots>
  236 + </pluginRepository>
  237 + <pluginRepository>
  238 + <id>muleforge-plugin-snapshots</id>
  239 + <name>Muleforge Snapshot Repository</name>
  240 + <url>http://repository.mulesoft.org/snapshots/</url>
  241 + <releases>
  242 + <enabled>false</enabled>
  243 + </releases>
  244 + <snapshots>
  245 + <enabled>true</enabled>
  246 + </snapshots>
  247 + </pluginRepository>
  248 + </pluginRepositories>
  249 +</project>
0  src/main/app/org/mule/module/esper/plugin.properties
No changes.
139 src/main/java/org/mule/module/esper/EsperConnector.java
... ... @@ -0,0 +1,139 @@
  1 +/**
  2 + * Mule Development Kit
  3 + * Copyright 2010-2011 (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
  4 + *
  5 + * Licensed under the Apache License, Version 2.0 (the "License");
  6 + * you may not use this file except in compliance with the License.
  7 + * You may obtain a copy of the License at
  8 + *
  9 + * http://www.apache.org/licenses/LICENSE-2.0
  10 + *
  11 + * Unless required by applicable law or agreed to in writing, software
  12 + * distributed under the License is distributed on an "AS IS" BASIS,
  13 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 + * See the License for the specific language governing permissions and
  15 + * limitations under the License.
  16 + */
  17 +
  18 +/**
  19 + * This file was automatically generated by the Mule Development Kit
  20 + */
  21 +package org.mule.module.esper;
  22 +
  23 +import com.espertech.esper.client.*;
  24 +import com.espertech.esper.event.map.MapEventBean;
  25 +import org.apache.commons.lang.StringUtils;
  26 +import org.apache.commons.logging.Log;
  27 +import org.apache.commons.logging.LogFactory;
  28 +import org.mule.api.ConnectionException;
  29 +import org.mule.api.MuleContext;
  30 +import org.mule.api.MuleMessage;
  31 +import org.mule.api.annotations.*;
  32 +import org.mule.api.annotations.param.Optional;
  33 +import org.mule.api.annotations.param.Payload;
  34 +import org.mule.api.callback.SourceCallback;
  35 +import org.mule.api.context.MuleContextAware;
  36 +
  37 +import java.net.URL;
  38 +
  39 +/**
  40 + * Cloud Connector for Esper.
  41 + *
  42 + * @author MuleSoft, Inc.
  43 + */
  44 +@Connector(name = "esper", schemaVersion = "1.0")
  45 +public class EsperConnector implements MuleContextAware {
  46 +
  47 + protected transient Log logger = LogFactory.getLog(getClass());
  48 +
  49 + private EPServiceProvider esperServiceProvider;
  50 +
  51 + private MuleContext muleContext;
  52 + /**
  53 + * The optional location of an Esper config file.
  54 + */
  55 + @Configurable
  56 + @Optional
  57 + private String configuration;
  58 +
  59 +
  60 + public void setConfiguration(String configuration) {
  61 + this.configuration = configuration;
  62 + }
  63 +
  64 +
  65 + public void setMuleContext(MuleContext muleContext) {
  66 + this.muleContext = muleContext;
  67 + }
  68 +
  69 +
  70 + @Connect
  71 + public void connect() throws ConnectionException {
  72 + Configuration c = new Configuration();
  73 +
  74 + if (StringUtils.isNotBlank(configuration)) {
  75 + logger.debug("Initializing EsperServiceProvider with configuration: " + configuration);
  76 + URL configURL = Thread.currentThread().getContextClassLoader().getResource(configuration);
  77 + c.configure(configURL);
  78 + }
  79 + esperServiceProvider = EPServiceProviderManager.getDefaultProvider(c);
  80 + }
  81 +
  82 + @Disconnect
  83 + public void disconnect() {
  84 + logger.debug("Destroying EsperServiceProvider");
  85 + esperServiceProvider.destroy();
  86 + }
  87 +
  88 + @ConnectionIdentifier
  89 + public String connectionId() {
  90 + return esperServiceProvider.getURI();
  91 + }
  92 +
  93 + @ValidateConnection
  94 + public boolean isConnected() {
  95 + return esperServiceProvider != null;
  96 + }
  97 +
  98 + /**
  99 + * Sends events to an Esper event stream.
  100 + * <p/>
  101 + * {@sample.xml ../../../doc/Esper-connector.xml.sample esper:send-event}
  102 + *
  103 + * @param eventPayload The event to be injected into the event stream.
  104 + */
  105 + @Processor
  106 + public void send(Object eventPayload) {
  107 + logger.debug(String.format("Sending event %s to stream", eventPayload));
  108 + esperServiceProvider.getEPRuntime().sendEvent(eventPayload);
  109 + }
  110 +
  111 + /**
  112 + * Listens for events matching the specified query statement.
  113 + * <p/>
  114 + * {@sample.xml ../../../doc/Esper-connector.xml.sample esper:listen}
  115 + *
  116 + * @param statement The Esper statement to select events from a stream.
  117 + * @param callback The callback to be called when a message is received
  118 + */
  119 + @Source
  120 + public void listen(String statement, final SourceCallback callback) {
  121 + logger.debug("Listening for events with statement: " + statement);
  122 + EPStatement s = esperServiceProvider.getEPAdministrator().createEPL(statement);
  123 + s.addListener(new SourceCallbackUpdateListener(callback));
  124 + }
  125 +
  126 + /**
  127 + * Utility transformer to extract a property from an <code>EventBean</code>.
  128 + * <p/>
  129 + * {@sample.xml ../../../doc/Esper-connector.xml.sample esper:get-event-property}
  130 + *
  131 + * @param event The <code>EventBean</code> to transform.
  132 + * @param key The property to extract
  133 + * @return The object corresponding to the parameter key
  134 + */
  135 + @Processor
  136 + public Object getEventProperty(@Payload EventBean event, String key) {
  137 + return event.get(key);
  138 + }
  139 +}
35 src/main/java/org/mule/module/esper/SourceCallbackUpdateListener.java
... ... @@ -0,0 +1,35 @@
  1 +package org.mule.module.esper;
  2 +
  3 +import com.espertech.esper.client.EventBean;
  4 +import com.espertech.esper.client.UpdateListener;
  5 +import org.apache.commons.logging.Log;
  6 +import org.apache.commons.logging.LogFactory;
  7 +import org.mule.api.callback.SourceCallback;
  8 +
  9 +
  10 +/**
  11 + * <code>UpdateListener</code> implementation that invokes the <code>SourceCallback</code> facilitate the
  12 + * dispatch of events as they are read off the event stream.
  13 + */
  14 +public class SourceCallbackUpdateListener implements UpdateListener {
  15 +
  16 + protected transient Log logger = LogFactory.getLog(getClass());
  17 +
  18 + SourceCallback sourceCallback;
  19 +
  20 + public SourceCallbackUpdateListener(SourceCallback sourceCallback) {
  21 + this.sourceCallback = sourceCallback;
  22 + }
  23 +
  24 + public void update(EventBean[] newEvents, EventBean[] oldEvents) {
  25 +
  26 + for (EventBean event : newEvents) {
  27 + try {
  28 + sourceCallback.process(event);
  29 + } catch (Exception e) {
  30 + logger.error("Could not process event: " + event, e);
  31 + }
  32 + }
  33 +
  34 + }
  35 +}
5 src/test/java/org/mule/module/esper/DummyEvent.java
... ... @@ -0,0 +1,5 @@
  1 +package org.mule.module.esper;
  2 +
  3 +public class DummyEvent {
  4 +
  5 +}
51 src/test/java/org/mule/module/esper/EsperModuleTest.java
... ... @@ -0,0 +1,51 @@
  1 +/**
  2 + * Mule Development Kit
  3 + * Copyright 2010-2011 (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
  4 + *
  5 + * Licensed under the Apache License, Version 2.0 (the "License");
  6 + * you may not use this file except in compliance with the License.
  7 + * You may obtain a copy of the License at
  8 + *
  9 + * http://www.apache.org/licenses/LICENSE-2.0
  10 + *
  11 + * Unless required by applicable law or agreed to in writing, software
  12 + * distributed under the License is distributed on an "AS IS" BASIS,
  13 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 + * See the License for the specific language governing permissions and
  15 + * limitations under the License.
  16 + */
  17 +
  18 +/**
  19 + * This file was automatically generated by the Mule Development Kit
  20 + */
  21 +package org.mule.module.esper;
  22 +
  23 +import org.mule.api.MuleMessage;
  24 +import org.mule.module.client.MuleClient;
  25 +import org.mule.tck.FunctionalTestCase;
  26 +
  27 +import org.junit.Test;
  28 +
  29 +public class EsperModuleTest extends FunctionalTestCase {
  30 + @Override
  31 + protected String getConfigResources() {
  32 + return "mule-config.xml";
  33 + }
  34 +
  35 + @Test
  36 + public void testCanInsertAndListenForEvent() throws Exception {
  37 +
  38 + MuleClient client = new MuleClient(muleContext);
  39 + DummyEvent dummyEvent = new DummyEvent();
  40 + client.dispatch("vm://in", dummyEvent, null);
  41 +
  42 + MuleMessage response = client.request("vm://out", 15000);
  43 + assertNotNull(response);
  44 + assertEquals("The output payload does not match the input payload", dummyEvent, response.getPayload());
  45 +
  46 + MuleMessage event = client.request("vm://events", 15000);
  47 + assertNotNull(event);
  48 + assertEquals(1L, event.getPayload());
  49 + }
  50 +
  51 +}
9 src/test/resources/esper-config.xml
... ... @@ -0,0 +1,9 @@
  1 +<esper-configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xmlns="http://www.espertech.com/schema/esper"
  3 + xsi:schemaLocation="
  4 + http://www.espertech.com/schema/esper
  5 + http://www.espertech.com/schema/esper/esper-configuration-2.0.xsd">
  6 +
  7 + <event-type name="TestEvent" class="org.mule.module.esper.DummyEvent"/>
  8 +
  9 +</esper-configuration>
16 src/test/resources/log4j.properties
... ... @@ -0,0 +1,16 @@
  1 +#Updated at Wed Oct 26 20:47:36 EDT 2011
  2 +#Wed Oct 26 20:47:36 EDT 2011
  3 +log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  4 +log4j.appender.R.File=application.log
  5 +log4j.rootLogger=error, stdout
  6 +log4j.appender.R.MaxFileSize=100KB
  7 +log4j.appender.R.layout=org.apache.log4j.PatternLayout
  8 +log4j.appender.R.MaxBackupIndex=1
  9 +log4j.logger.org.springframework=INFO
  10 +log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
  11 +log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
  12 +log4j.logger.org.mule=INFO
  13 +log4j.logger.org.mule.module.esper=DEBUG
  14 +log4j.logger.com.espertech.esper=INFO
  15 +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  16 +log4j.appender.R=org.apache.log4j.RollingFileAppender
48 src/test/resources/mule-config.xml
... ... @@ -0,0 +1,48 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!--
  3 +
  4 + Mule Development Kit
  5 + Copyright 2010-2011 (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
  6 +
  7 + Licensed under the Apache License, Version 2.0 (the "License");
  8 + you may not use this file except in compliance with the License.
  9 + You may obtain a copy of the License at
  10 +
  11 + http://www.apache.org/licenses/LICENSE-2.0
  12 +
  13 + Unless required by applicable law or agreed to in writing, software
  14 + distributed under the License is distributed on an "AS IS" BASIS,
  15 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16 + See the License for the specific language governing permissions and
  17 + limitations under the License.
  18 +
  19 +-->
  20 +
  21 +<mule xmlns="http://www.mulesoft.org/schema/mule/core"
  22 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  23 + xmlns:spring="http://www.springframework.org/schema/beans"
  24 + xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
  25 + xmlns:esper="http://www.mulesoft.org/schema/mule/esper"
  26 +
  27 + xsi:schemaLocation="
  28 + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  29 + http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
  30 + http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.2/mule-vm.xsd
  31 + http://www.mulesoft.org/schema/mule/esper http://www.mulesoft.org/schema/mule/esper/1.0/mule-esper.xsd">
  32 +
  33 + <esper:config configuration="esper-config.xml"/>
  34 +
  35 + <flow name="testFlow">
  36 + <vm:inbound-endpoint path="in"/>
  37 + <esper:send eventPayload-ref="#[payload:]"/>
  38 + <vm:outbound-endpoint path="out"/>
  39 + </flow>
  40 +
  41 + <flow name="Event Listener Flow">
  42 + <esper:listen statement="select count(*) from TestEvent
  43 + .win:time_batch(5, 'FORCE_UPDATE, START_EAGER') having count(*) &gt; 0"/>
  44 + <esper:get-event-property key="count(*)"/>
  45 + <vm:outbound-endpoint path="events"/>
  46 + </flow>
  47 +
  48 +</mule>

0 comments on commit a6f37ca

Please sign in to comment.
Something went wrong with that request. Please try again.