You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2009/08/10 07:14:52 UTC

svn commit: r802651 - in /synapse/trunk/java: modules/distribution/src/main/conf/ modules/samples/src/main/java/samples/userguide/ repository/conf/ src/site/xdoc/

Author: hiranya
Date: Mon Aug 10 05:14:51 2009
New Revision: 802651

URL: http://svn.apache.org/viewvc?rev=802651&view=rev
Log:
Adding a sample demonstrating the Synapse observer interface. Updated the synapse extending guide with details on how to write a Synapse observer.


Added:
    synapse/trunk/java/modules/samples/src/main/java/samples/userguide/SimpleLoggingObserver.java
Modified:
    synapse/trunk/java/modules/distribution/src/main/conf/log4j.properties
    synapse/trunk/java/repository/conf/synapse.properties
    synapse/trunk/java/src/site/xdoc/Synapse_Extending.xml
    synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml

Modified: synapse/trunk/java/modules/distribution/src/main/conf/log4j.properties
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/distribution/src/main/conf/log4j.properties?rev=802651&r1=802650&r2=802651&view=diff
==============================================================================
--- synapse/trunk/java/modules/distribution/src/main/conf/log4j.properties (original)
+++ synapse/trunk/java/modules/distribution/src/main/conf/log4j.properties Mon Aug 10 05:14:51 2009
@@ -37,6 +37,7 @@
 log4j.category.samples.util=INFO
 #log4j.category.org.apache.synapse.transport.nhttp.util=DEBUG
 #log4j.category.org.apache.http.impl.nio.reactor=DEBUG
+#log4j.category.samples.userguide=INFO
 
 # The console appender is used to display general information at console
 log4j.appender.CONSOLE_APPENDER=org.apache.log4j.ConsoleAppender

Added: synapse/trunk/java/modules/samples/src/main/java/samples/userguide/SimpleLoggingObserver.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/SimpleLoggingObserver.java?rev=802651&view=auto
==============================================================================
--- synapse/trunk/java/modules/samples/src/main/java/samples/userguide/SimpleLoggingObserver.java (added)
+++ synapse/trunk/java/modules/samples/src/main/java/samples/userguide/SimpleLoggingObserver.java Mon Aug 10 05:14:51 2009
@@ -0,0 +1,40 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, 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.
+ */
+
+package samples.userguide;
+
+import org.apache.synapse.config.AbstractSynapseObserver;
+import org.apache.synapse.config.Entry;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.Startup;
+import org.apache.synapse.eventing.SynapseEventSource;
+import org.apache.synapse.core.axis2.ProxyService;
+import org.apache.synapse.endpoints.Endpoint;
+
+/**
+ * This sample observer implementation simply calls the event handlers defined
+ * in the AbstractSynapseObserver super class.
+ */
+public class SimpleLoggingObserver extends AbstractSynapseObserver {
+
+    public SimpleLoggingObserver() {
+        super();
+        log.info("Simple logging observer initialized...Capturing Synapse events...");
+    }
+}

Modified: synapse/trunk/java/repository/conf/synapse.properties
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/synapse.properties?rev=802651&r1=802650&r2=802651&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/synapse.properties (original)
+++ synapse/trunk/java/repository/conf/synapse.properties Mon Aug 10 05:14:51 2009
@@ -35,6 +35,10 @@
 #synapse.temp_data.chunk.threshold=1024
 #synapse.temp_data.chunk.size=1024
 #
+# Register any Synapse observers here
+# Specify multiple observer implementation as a comma separated list
+#synapse.observers=samples.userguide.SimpleLoggingObserver
+#
 #############################################################################
 # Security Configuration
 #############################################################################

Modified: synapse/trunk/java/src/site/xdoc/Synapse_Extending.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Extending.xml?rev=802651&r1=802650&r2=802651&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Extending.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Extending.xml Mon Aug 10 05:14:51 2009
@@ -482,5 +482,43 @@
         org.apache.synapse.config.xml.MediatorFactory
         org.apache.synapse.config.xml.MediatorSerializer
     /... the implementation classes as usual...</pre>
+    <h2 id="synObservers">
+        Writing Synapse Observers
+    </h2>
+    <p>
+       A Synapse observer is developed by either implementing the
+       org.apache.synapse.config.SynapseObserver interface or by extending the
+       org.apache.synapse.config.AbstractSynapseObserver class. A Synapse observer is notified
+       by the Synapse configuration when new elements are added to the configuration and
+       when existing elements are removed from the configuration. The following event
+       handlers are available to the Synapse observer implementations.
+    </p>
+<pre xml:space="preserve">
+ public void sequenceAdded(Mediator sequence);
+ public void sequenceRemoved(Mediator sequence);
+ public void entryAdded(Entry entry);
+ public void entryRemoved(Entry entry);
+ public void endpointAdded(Endpoint endpoint);
+ public void endpointRemoved(Endpoint endpoint);
+ public void proxyServiceAdded(ProxyService proxy);
+ public void proxyServiceRemoved(ProxyService proxy);
+ public void startupAdded(Startup startup);
+ public void startupRemoved(Startup startup);
+ public void eventSourceAdded(SynapseEventSource eventSource);
+ public void eventSourceRemoved(SynapseEventSource eventSource);
+</pre>
+     <p>
+         The AbstractSynapseObserver provides default implementations to all these
+         event handlers. It simply logs any received events.
+     </p>
+     <p>
+         In situations where the custom code has access to the SynapseConfiguration class
+         observers can be directly registered with the SynapseConfiguration by using the
+         registerObserver(SynapseObserver o) method. Otherwise SynapseObserver implementations
+         can be defined in the synapse.properties file which resides in the SYNAPSE_HOME/lib
+         directory. The following example shows how two observers are registered with the
+         Synapse configuration using the synapse.properties file.
+     </p>
+     <pre xml:space="preserve">synapse.observers=test.LoggingObserverImpl, test.SimpleObserverImpl</pre>
   </body>
 </document>
\ No newline at end of file

Modified: synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml?rev=802651&r1=802650&r2=802651&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml Mon Aug 10 05:14:51 2009
@@ -311,6 +311,9 @@
                 <li>
                     <a href="#Sample600">Sample 600: File hierarchy based configuration builder</a>
                 </li>
+                <li>
+                    <a href="#Sample601">Sample 601: Using Synapse Observers</a>
+                </li>
             </ul>
         </li>
 </ul></div>
@@ -4314,5 +4317,58 @@
             This feature comes in handy when managing large Synapse configurations. It is easier to maintain a well structured
             file hierarchy than managing one large flat XML file.
          </p>
-       </div>       
+       </div>
+       <h2>
+         <a name="Sample601" id="Sample601">Sample 601: Using Synapse observers</a>
+       </h2>
+       <div>
+         <p>
+           <strong>Objective:</strong> Demonstrate the ability to monitor the Synapse configuration at runtime using the
+             SynapseObserver interface
+         </p>
+         <p>
+           Open the synapse.properties file in the SYNAPSE_HOME/lib directory using a text editor and uncomment the line which
+           defines the simple logging Synapse observer.
+         </p>
+         <pre xml:space="preserve">synapse.observers=samples.userguide.SimpleLoggingObserver</pre>
+         <p>
+           Open the log4j.properties file in the SYNAPSE_HOME/lib directory and uncomment the line which sets the INFO log
+           level to the samples.userguide package.
+         </p>
+         <pre xml:space="preserve">log4j.category.samples.userguide=INFO</pre>
+         <p>
+           Start Synapse using any of the sample configurations. The SimpleLoggingObserver will capture events that occur
+           while constructing the Synapse configuration and log them on the console as follows.
+         </p>
+         <pre xml:space="preserve">
+ 2009-08-06 14:30:24,578 [-] [main]  INFO SimpleLoggingObserver Simple logging observer initialized...Capturing Synapse events...
+ 2009-08-06 14:30:24,604 [-] [main]  INFO SimpleLoggingObserver Endpoint : a3 was added to the Synapse configuration successfully
+ 2009-08-06 14:30:24,605 [-] [main]  INFO SimpleLoggingObserver Endpoint : a2 was added to the Synapse configuration successfully
+ 2009-08-06 14:30:24,606 [-] [main]  INFO SimpleLoggingObserver Endpoint : null was added to the Synapse configuration successfully
+ 2009-08-06 14:30:24,611 [-] [main]  INFO SimpleLoggingObserver Local entry : a1 was added to the Synapse configuration successfully
+ 2009-08-06 14:30:24,649 [-] [main]  INFO SimpleLoggingObserver Proxy service : StockQuoteProxy2 was added to the Synapse configuration successfully
+ 2009-08-06 14:30:24,661 [-] [main]  INFO SimpleLoggingObserver Proxy service : StockQuoteProxy1 was added to the Synapse configuration successfully
+ 2009-08-06 14:30:24,664 [-] [main]  INFO SimpleLoggingObserver Sequence : main was added to the Synapse configuration successfully
+ 2009-08-06 14:30:24,701 [-] [main]  INFO SimpleLoggingObserver Sequence : fault was added to the Synapse configuration successfully</pre>
+
+         <p>
+           The SimpleLoggingObserver is implemented as follows. It does not override any of the event handler implementations
+           in the AbstractSynapseObserver class. The AbstractSynapseObserver logs all the received events by default.
+         </p>
+         <pre xml:space="preserve">
+    package samples.userguide;
+
+    import org.apache.synapse.config.AbstractSynapseObserver;
+
+    public class SimpleLoggingObserver extends AbstractSynapseObserver {
+
+        public SimpleLoggingObserver() {
+            super();
+            log.info("Simple logging observer initialized...Capturing Synapse events...");
+        }
+    }</pre>
+         <p>
+           Refer Synapse <a href="Synapse_Extending.html#synObservers">Synapse Extending Guide</a> for more details on developing Synapse observers.
+         </p>
+       </div>
 </body></document>