[overlord-commits] Overlord SVN: r173 - in sam/trunk/modules/core/src/main/java: org and 8 other directories.
overlord-commits at lists.jboss.org
overlord-commits at lists.jboss.org
Wed Jul 16 06:46:27 EDT 2008
Author: heiko.braun at jboss.com
Date: 2008-07-16 06:46:26 -0400 (Wed, 16 Jul 2008)
New Revision: 173
Added:
sam/trunk/modules/core/src/main/java/org/
sam/trunk/modules/core/src/main/java/org/jboss/
sam/trunk/modules/core/src/main/java/org/jboss/sam/
sam/trunk/modules/core/src/main/java/org/jboss/sam/EventMessage.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/ProcessingStatement.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInput.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInputCallback.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamOutput.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/Chart.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartBuilder.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMapping.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistry.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistryFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMetadata.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServer.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServerFactory.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/PropertyMapping.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/BarChartBuilder.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/JFreeChartImpl.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/LineChartBuilder.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/PieChartBuilder.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperProcessingStatement.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperRuntimeImpl.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EventAdapter.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/StreamOutputAdapter.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMDispatcher.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamInput.java
sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamRegistry.java
Removed:
sam/trunk/modules/core/src/main/java/java/
Log:
Cleanup core module
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/EventMessage.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/EventMessage.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/EventMessage.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+import java.util.Iterator;
+
+/**
+ * An event message will be send when an Event occurs.<br>
+ * It consist of a timestamp and associated event properties.
+ * EventMessage's are written to {@link org.jboss.sam.StreamOutput}'s.
+ * <p>
+ * EventMessage's can be mapped to {@link org.jboss.sam.chart.Chart}'s.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface EventMessage<T>
+{
+ /**
+ * Creation timestamp.
+ * @return
+ */
+ long getTimestamp();
+
+ /**
+ * Get an event property by name
+ * @param name
+ * @return
+ */
+ Object getProperty(String name);
+
+ /**
+ * Iterate over event property names
+ * @return
+ */
+ Iterator<String> getPropertyNames();
+
+ /**
+ * Access the underlying implementation
+ * @return
+ */
+ T getUnderlying();
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/EventMessage.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+import java.util.Iterator;
+
+/**
+ * An event processor glues together {@link org.jboss.sam.StreamInput} and {@link org.jboss.sam.StreamOutput}
+ * and provides a way to register {@link org.jboss.sam.ProcessingStatement}'s,
+ * both bound (event forwarding) and unbound (event aggregation and filtering).
+ * <p>
+ * Instances are created through {@link org.jboss.sam.EventProcessorFactory}
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface EventProcessor<T>
+{
+ /**
+ * Add input to the runtime
+ * @param streamInput
+ */
+ void addInput(StreamInput streamInput);
+
+ /**
+ * Remove input from the runtime
+ * @param streamName
+ */
+ void removeInput(String streamName);
+
+ /**
+ * Add output to the runtime
+ * @param streamOutput
+ */
+ void addOutput(StreamOutput streamOutput);
+
+ /**
+ * Remove output from the runtime
+ * @param streamName
+ */
+ void removeOutput(String streamName);
+
+ /**
+ * Iterate over input stream names
+ * @return
+ */
+ Iterator<String> getStreamInputNames();
+
+ /**
+ * Iterate over output stream names
+ * @return
+ */
+ Iterator<String> getStreamOutputNames();
+
+ /**
+ * Creates a statement
+ *
+ * @param statementName
+ * @param epl
+ * @return
+ */
+ ProcessingStatement registerStatement(String statementName, String epl);
+
+ /**
+ * Creates a statement and binds it to an output stream.
+ *
+ * @param streamOutputName
+ * @param statementName
+ * @param epl
+ * @return
+ */
+ ProcessingStatement registerBoundStatement(String streamOutputName, String statementName, String epl);
+
+ /**
+ * Cleanup a statement and remove it
+ * @param statementName
+ */
+ void clearStatement(String statementName);
+
+ /**
+ * Cleanup all statements and remove them
+ */
+ void clearAllStatements();
+
+ /**
+ * Iterate over statement names
+ * @return
+ */
+ Iterator<String> getStatementNames();
+
+ String getName();
+
+ T getUnderlying();
+
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+import org.jboss.sam.internal.esper.EsperRuntimeImpl;
+
+import java.net.URL;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public abstract class EventProcessorFactory
+{
+ protected EventProcessorFactory()
+ {
+ }
+
+ public static EventProcessorFactory newInstance()
+ {
+ return new DefaultEventProcessorFactory();
+ }
+
+ public abstract EventProcessor createRuntime(String name, URL config);
+
+ static class DefaultEventProcessorFactory extends EventProcessorFactory
+ {
+
+ public EventProcessor createRuntime(String name, URL config)
+ {
+ return new EsperRuntimeImpl(name, config);
+ }
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/EventProcessorFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/ProcessingStatement.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/ProcessingStatement.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/ProcessingStatement.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+/**
+ * Represents an EPL (event processing languge) statement.
+ * Statements are associated with a {@link org.jboss.sam.EventProcessor}
+ * and can be bound to a {@link org.jboss.sam.StreamOutput} to forward events,
+ * or used unbound to aggregate and filter events.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface ProcessingStatement<T>
+{
+ /**
+ * Statements are managed by name
+ * @return
+ */
+ String getName();
+
+ /**
+ * Get the EPL expression this statement was created from
+ * @return
+ */
+ String getExpression();
+
+ /**
+ * Check wether the statement is bound to a {@link org.jboss.sam.StreamOutput}
+ * @return
+ */
+ boolean isBound();
+
+ /**
+ * Access the underlying implementation
+ * @return
+ */
+ T getUnderlying();
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/ProcessingStatement.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInput.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInput.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInput.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+/**
+ * Stream inputs are registered with {@link org.jboss.sam.EventProcessor}'s
+ * and notify registered {@link org.jboss.sam.StreamInputCallback}'s when new events arrive.
+ * Typically the CEP runtime itself act's as such a listener in order to finished events.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface StreamInput<T>
+{
+ <T extends StreamInput> T start();
+
+ <T extends StreamInput> T stop();
+
+ boolean isStarted();
+
+ /**
+ * Register a callback
+ * @param streamInputCallback an event processing instance
+ */
+ void registerCallback(StreamInputCallback streamInputCallback);
+
+ /**
+ * Remove all registered callbacks
+ */
+ void clearCallbacks();
+
+ /**
+ * Stream input name
+ * @return
+ */
+ String getStreamName();
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInput.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInputCallback.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInputCallback.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInputCallback.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+/**
+ * Registered with a {@link StreamInput} and will be notified when new events arrive.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface StreamInputCallback
+{
+ void onEvent(Object args);
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamInputCallback.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamOutput.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamOutput.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamOutput.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam;
+
+/**
+ * Stream outputs are used to forward events. Typically the last step
+ * of an event processing chain leads to an action which receive events through
+ * the <code>write(...)</code> method.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface StreamOutput<T>
+{
+ <T extends StreamOutput> T start();
+
+ <T extends StreamOutput> T stop();
+
+ boolean isStarted();
+
+ /**
+ * Receive forwarded events
+ * @param args an event stream
+ */
+ void write(EventMessage[] args);
+
+ /**
+ * Stream output name
+ * @return
+ */
+ String getStreamName();
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/StreamOutput.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/Chart.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/Chart.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/Chart.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+import java.io.OutputStream;
+
+/**
+ * A chart repesentation.<br>
+ * Can be an in-memory representation or a link to a physical
+ * artifact (caching).
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface Chart<T>
+{
+ String getName();
+
+ void writeTo(OutputStream out);
+
+ T getUnderlying();
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/Chart.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartBuilder.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartBuilder.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartBuilder.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+import org.jboss.sam.EventMessage;
+
+/**
+ * Builds charts from payload and mapping information.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface ChartBuilder
+{
+ ChartMetadata getMetadata();
+
+ Chart buildChart(EventMessage[] events, ChartMapping mapping);
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMapping.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMapping.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMapping.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+import java.util.Collections;
+import java.util.List;
+import java.io.Serializable;
+
+/**
+ * An immutable mapping of index and data values,
+ * that can be passed to a {@link org.jboss.sam.chart.ChartBuilder} to construct
+ * {@link org.jboss.sam.chart.Chart}'s. Each instance is identifed by an alias name
+ * and will be maintained through a {@link ChartMappingRegistry}.
+ * <p>
+ * ChartMappings should be created once and reused.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public final class ChartMapping implements Serializable
+{
+ String aliasName;
+
+ List<PropertyMapping> indexMappings;
+
+ List<PropertyMapping> propertyMappings;
+
+ public ChartMapping(String aliasName, List<PropertyMapping> indexMappings, List<PropertyMapping> propertyMappings)
+ {
+ this.aliasName = aliasName;
+ this.indexMappings = Collections.unmodifiableList(indexMappings);
+ this.propertyMappings = Collections.unmodifiableList(propertyMappings);
+ }
+
+ String getAliasName()
+ {
+ return this.aliasName;
+ }
+
+ /**
+ * Returns an immutable index mapping for a key.
+ * The key is specified in {@link org.jboss.sam.chart.ChartMetadata}
+ * @return
+ */
+ public PropertyMapping getIndexMapping(String key)
+ {
+ PropertyMapping indexMapping = resolveKey(key, indexMappings);
+ if(null==indexMapping)
+ throw new IllegalArgumentException("Failed to resolved index mapping by key: "+ key);
+
+ return indexMapping;
+ }
+
+ /**
+ * Returns an immutable data mapping
+ * @return
+ */
+ public PropertyMapping getPropertyMapping(String key)
+ {
+ PropertyMapping dataMapping = resolveKey(key, propertyMappings);
+ if(null==dataMapping)
+ throw new IllegalArgumentException("Failed to resolved data mapping by key: "+ key);
+
+ return dataMapping;
+ }
+
+ private PropertyMapping resolveKey(String key, List<PropertyMapping> mappings)
+ {
+ PropertyMapping mapping = null;
+ for(PropertyMapping index : mappings)
+ {
+ if(index.getTargetKey().equals(key))
+ {
+ mapping = index;
+ break;
+ }
+ }
+
+ return mapping;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMapping.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistry.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistry.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistry.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+/**
+ * Maintains {@link ChartMapping}'s.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface ChartMappingRegistry
+{
+ void registerChartMapping(ChartMapping chartMaping);
+
+ ChartMapping getChartMapping(String aliasName);
+
+ void clearChartMapping(String aliasName);
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistry.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistryFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistryFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistryFactory.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public abstract class ChartMappingRegistryFactory
+{
+ abstract ChartMappingRegistry createChartMappingRegistry();
+
+ public static ChartMappingRegistryFactory newInstance()
+ {
+ return new DefaultChartMappingRegistryFactory();
+ }
+
+ static class DefaultChartMappingRegistryFactory extends ChartMappingRegistryFactory
+ {
+
+ ChartMappingRegistry createChartMappingRegistry()
+ {
+ throw new RuntimeException("Not implemented");
+ }
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMappingRegistryFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMetadata.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMetadata.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMetadata.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+import java.util.Iterator;
+
+/**
+ * Metadata for chart types associated with a {@link org.jboss.sam.chart.ChartBuilder}
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface ChartMetadata
+{
+ String getTypeName();
+
+ Iterator<String> getSupportedIndexNames();
+
+ Iterator<String> getSupportedPropertyNames();
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartMetadata.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServer.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServer.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServer.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+import org.jboss.sam.EventMessage;
+
+/**
+ * Allows creation and retrieval of {@link org.jboss.sam.chart.Chart} repesentations.
+ * A chart server will be associated with a {@link org.jboss.sam.chart.ChartMappingRegistry} that stores
+ * the preconfigured mappings.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public interface ChartServer
+{
+ /**
+ * Get chart by name
+ * @param chartName
+ * @return
+ */
+ Chart getChart(String chartName);
+
+ /**
+ * Create a new chart under a given name
+ * @param chartName
+ * @param payloads
+ * @return
+ */
+ Chart createChart(String chartName, String chartMappingAlias, EventMessage[] payloads);
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServer.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServerFactory.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServerFactory.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServerFactory.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public abstract class ChartServerFactory
+{
+ abstract ChartServer createChartServer();
+
+ public static ChartServerFactory newInstance()
+ {
+ return new DefaultChartServerFactory();
+ }
+
+ static class DefaultChartServerFactory extends ChartServerFactory
+ {
+ ChartServer createChartServer()
+ {
+ throw new RuntimeException("Not implemented");
+ }
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/ChartServerFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/PropertyMapping.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/PropertyMapping.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/PropertyMapping.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart;
+
+import org.jboss.sam.EventMessage;
+
+import java.io.Serializable;
+
+/**
+ * Maps {@link org.jboss.sam.EventMessage} properties
+ * to chart attributes, like X-Axis and Y-Axis values.<br>
+ * Supports constants.
+ *
+ * @see org.jboss.sam.chart.ChartMapping
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public final class PropertyMapping implements Serializable
+{
+ /**
+ * The key to which a mapped property will be assigned
+ */
+ private String targetKey;
+
+ /**
+ * Name of the mapped {@link org.jboss.sam.EventMessage} property
+ */
+ private String sourcePropertyName;
+
+ private String constantValue = null;
+
+ public PropertyMapping(String targetKey, String sourcePropertyName)
+ {
+ this.targetKey = targetKey;
+ this.sourcePropertyName = sourcePropertyName;
+ }
+
+ public String getTargetKey()
+ {
+ return targetKey;
+ }
+
+ public PropertyMapping constant(String constant)
+ {
+ this.constantValue = constant.intern();
+ return this;
+ }
+
+ /**
+ * Retrieve an {@link org.jboss.sam.EventMessage} value
+ * by mapping to {@link #sourcePropertyName}
+ * @param payload
+ * @return
+ */
+ public Object map(EventMessage payload)
+ {
+ Object mapping;
+ if(null==constantValue)
+ mapping = payload.getProperty(sourcePropertyName);
+ else
+ mapping = constantValue;
+
+ return mapping;
+ }
+
+
+ public String toString()
+ {
+ String prop = sourcePropertyName != null ? sourcePropertyName : "CONSTANT";
+ return targetKey +"->"+prop;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/PropertyMapping.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/BarChartBuilder.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/BarChartBuilder.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/BarChartBuilder.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart.internal.jfree;
+
+import org.jboss.sam.EventMessage;
+import org.jboss.sam.chart.Chart;
+import org.jboss.sam.chart.ChartBuilder;
+import org.jboss.sam.chart.ChartMapping;
+import org.jboss.sam.chart.ChartMetadata;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.CategoryDataset;
+import org.jfree.data.category.DefaultCategoryDataset;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class BarChartBuilder implements ChartBuilder
+{
+ private String chartTitle;
+ private String domainAxisLabel, rangeAxisLabel;
+
+ public final static String INDEX_1 = "series";
+ public final static String INDEX_2 = "x_value";
+ public final static String PROP_1 = "y_value";
+
+ public static List<String> INDEXES = new ArrayList<String>();
+ public static List<String> PROPS = new ArrayList<String>();
+
+ static
+ {
+ INDEXES.add(INDEX_1);
+ INDEXES.add(INDEX_2);
+
+ PROPS.add(PROP_1);
+ }
+
+ public BarChartBuilder(String chartTitle, String domainAxisLabel, String rangeAxisLabel)
+ {
+ this.chartTitle = chartTitle;
+ this.domainAxisLabel = domainAxisLabel;
+ this.rangeAxisLabel = rangeAxisLabel;
+ }
+
+ public ChartMetadata getMetadata()
+ {
+ return new ChartMetadata() {
+
+ public String getTypeName()
+ {
+ return "BarChart";
+ }
+
+ public Iterator<String> getSupportedIndexNames()
+ {
+ return INDEXES.iterator();
+ }
+
+ public Iterator<String> getSupportedPropertyNames()
+ {
+ return PROPS.iterator();
+ }
+ };
+ }
+
+ public Chart buildChart(EventMessage[] events, ChartMapping mapping)
+ {
+ CategoryDataset dataset = createDataset(events, mapping);
+
+ JFreeChart chart = org.jfree.chart.ChartFactory.createBarChart(
+ chartTitle, // chart title
+ domainAxisLabel, // domain axis label
+ rangeAxisLabel, // range axis label
+ dataset, // data
+ PlotOrientation.VERTICAL,
+ true, // include legend
+ true, // tooltips?
+ false // URLs?
+ );
+
+ //customize(chart);
+
+ return new JFreeChartImpl(chart);
+ }
+
+ private CategoryDataset createDataset(EventMessage[] payloads, ChartMapping mapping)
+ {
+ DefaultCategoryDataset dataset = new DefaultCategoryDataset();
+
+ for(EventMessage event : payloads)
+ {
+ Number number = (Number) (mapping.getPropertyMapping(PROP_1)).map(event);
+ Comparable c1 = (Comparable) (mapping.getIndexMapping(INDEX_1)).map(event);
+ Comparable c2 = (Comparable) (mapping.getIndexMapping(INDEX_2)).map(event);
+ dataset.addValue(
+ number, // value
+ c1, // seriesName
+ c2 // category
+ );
+ }
+
+ return dataset;
+ }
+
+ /**
+ * Example customization
+ *
+ * @todo Create common look and feel
+ *
+ * @param chart
+ */
+ /*private void customize(JFreeChart chart)
+ {
+ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
+ // set the background color for the chart...
+ chart.setBackgroundPaint(new Color(0xBBBBDD));
+ // get a reference to the plot for further customisation...
+ CategoryPlot plot = chart.getCategoryPlot();
+ // set the range axis to display integers only...
+ NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
+ rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
+ // disable bar outlines...
+ BarRenderer renderer = (BarRenderer) plot.getRenderer();
+ renderer.setCreateEntities(true);
+
+ // set up gradient paints for series...
+ GradientPaint gp0 = new GradientPaint(
+ 0.0f, 0.0f, Color.blue,
+ 0.0f, 0.0f, Color.lightGray
+ );
+ GradientPaint gp1 = new GradientPaint(
+ 0.0f, 0.0f, Color.green,
+ 0.0f, 0.0f, Color.lightGray
+ );
+ GradientPaint gp2 = new GradientPaint(
+ 0.0f, 0.0f, Color.red,
+ 0.0f, 0.0f, Color.lightGray
+ );
+ renderer.setSeriesPaint(0, gp0);
+ renderer.setSeriesPaint(1, gp1);
+ renderer.setSeriesPaint(2, gp2);
+
+ // OPTIONAL CUSTOMISATION COMPLETED.
+ } */
+
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/BarChartBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/JFreeChartImpl.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/JFreeChartImpl.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/JFreeChartImpl.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart.internal.jfree;
+
+import org.jboss.sam.chart.Chart;
+import org.jboss.sam.chart.ChartMetadata;
+import org.jfree.chart.JFreeChart;
+
+import java.io.OutputStream;
+import java.util.UUID;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class JFreeChartImpl implements Chart<JFreeChart>
+{
+ private ChartMetadata metadata;
+
+ private JFreeChart delegate;
+
+ private String name;
+
+ public JFreeChartImpl(String name, JFreeChart delegate)
+ {
+ this.name = name;
+ this.delegate = delegate;
+ }
+
+ public JFreeChartImpl(JFreeChart delegate)
+ {
+ this(UUID.randomUUID().toString(), delegate);
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void writeTo(OutputStream out)
+ {
+ throw new RuntimeException("Not implemented");
+ }
+
+ public JFreeChart getUnderlying()
+ {
+ return delegate;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/JFreeChartImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/LineChartBuilder.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/LineChartBuilder.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/LineChartBuilder.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart.internal.jfree;
+
+import org.jboss.sam.EventMessage;
+import org.jboss.sam.chart.Chart;
+import org.jboss.sam.chart.ChartBuilder;
+import org.jboss.sam.chart.ChartMapping;
+import org.jboss.sam.chart.ChartMetadata;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+
+import java.util.Iterator;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class LineChartBuilder implements ChartBuilder
+{
+ private String chartTitle;
+ private String xAxisLabel,yAxisLabel;
+
+ public final static String INDEX_1 = "series";
+ public final static String INDEX_2 = "x_value";
+ public final static String DATA_1 = "y_value";
+
+ public LineChartBuilder(String chartTitle, String xAxisLabel, String yAxisLabel)
+ {
+ this.chartTitle = chartTitle;
+ this.xAxisLabel = xAxisLabel;
+ this.yAxisLabel = yAxisLabel;
+ }
+
+ public ChartMetadata getMetadata()
+ {
+ return null;
+ }
+
+ public Chart buildChart(EventMessage[] events, ChartMapping mapping)
+ {
+ XYSeriesCollection dataset = createDataset(events, mapping);
+
+ JFreeChart chart = ChartFactory.createXYLineChart(
+ chartTitle, // chart title
+ xAxisLabel, // x axis label
+ yAxisLabel, // y axis label
+ dataset, // data
+ PlotOrientation.VERTICAL,
+ true, // include legend
+ true, // tooltips
+ false // urls
+ );
+
+ return new JFreeChartImpl(chart);
+ }
+
+ private XYSeriesCollection createDataset(EventMessage[] events, ChartMapping mapping)
+ {
+
+ XYSeriesCollection dataset = new XYSeriesCollection();
+
+ for(EventMessage event : events)
+ {
+ XYSeries series = getOrCreateSeries(
+ dataset,
+ (String)mapping.getIndexMapping(INDEX_1).map(event)
+ );
+ series.add(
+ (Double)mapping.getIndexMapping(INDEX_2).map(event),
+ (Double)mapping.getPropertyMapping(DATA_1).map(event)
+ );
+ }
+
+ return dataset;
+ }
+
+ private XYSeries getOrCreateSeries(XYSeriesCollection dataset, Comparable key)
+ {
+ XYSeries match = null;
+ Iterator it = dataset.getSeries().iterator();
+ while(it.hasNext())
+ {
+ XYSeries series = (XYSeries)it.next();
+ if(series.getKey().equals(key))
+ {
+ match = series;
+ break;
+ }
+ }
+
+ if(null==match)
+ {
+ match = new XYSeries(key);
+ dataset.addSeries(match);
+ }
+
+ return match;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/LineChartBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/PieChartBuilder.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/PieChartBuilder.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/PieChartBuilder.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.chart.internal.jfree;
+
+import org.jboss.sam.EventMessage;
+import org.jboss.sam.chart.Chart;
+import org.jboss.sam.chart.ChartBuilder;
+import org.jboss.sam.chart.ChartMapping;
+import org.jboss.sam.chart.ChartMetadata;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.data.general.DefaultPieDataset;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class PieChartBuilder implements ChartBuilder
+{
+ private String chartName;
+ //private DefaultPieDataset dataset;
+
+ public final static String INDEX_1 = "category";
+ public final static String DATA_1 = "percentage";
+
+ public PieChartBuilder(String chartName)
+ {
+ this.chartName = chartName;
+ }
+
+
+ public ChartMetadata getMetadata()
+ {
+ return null;
+ }
+
+ public Chart buildChart(EventMessage[] events, ChartMapping mapping)
+ {
+ DefaultPieDataset dataset = createDataset(events, mapping);
+
+ JFreeChart chart = ChartFactory.createPieChart(
+ chartName,
+ dataset,
+ true, // legend?
+ true, // tooltips?
+ false // URLs?
+ );
+
+ return new JFreeChartImpl(chart);
+ }
+
+ private DefaultPieDataset createDataset(EventMessage[] events, ChartMapping mapping)
+ {
+ DefaultPieDataset dataset = new DefaultPieDataset();
+
+ for(EventMessage event : events)
+ {
+ dataset.setValue(
+ (String)mapping.getIndexMapping(INDEX_1).map(event), // category
+ (Double)mapping.getPropertyMapping(DATA_1).map(event) // percentage
+ );
+ }
+
+ return dataset;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/chart/internal/jfree/PieChartBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperProcessingStatement.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperProcessingStatement.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperProcessingStatement.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.esper;
+
+import com.espertech.esper.client.EPStatement;
+import org.jboss.sam.ProcessingStatement;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class EsperProcessingStatement implements ProcessingStatement<EPStatement>
+{
+ private EPStatement delegate;
+
+ protected String name;
+
+ private boolean bound;
+
+ public EsperProcessingStatement(EPStatement delegate)
+ {
+ this(delegate, false);
+ }
+
+ public EsperProcessingStatement(EPStatement delegate, boolean isBound)
+ {
+ this.bound = isBound;
+ this.delegate = delegate;
+ }
+
+ public String getName()
+ {
+ return this.name;
+ }
+
+ public boolean isBound()
+ {
+ return this.bound;
+ }
+
+ public String getExpression()
+ {
+ return delegate.getText();
+ }
+
+ public EPStatement getUnderlying()
+ {
+ return delegate;
+ }
+
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperProcessingStatement.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperRuntimeImpl.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperRuntimeImpl.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperRuntimeImpl.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,160 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.esper;
+
+import com.espertech.esper.client.*;
+import org.jboss.sam.*;
+
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A SAM runtime implementation that builds atop of Esper.
+ * It processes imput streams and passes event representations to the underlying Esper instance.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class EsperRuntimeImpl implements StreamInputCallback, EventProcessor<EPServiceProvider>
+{
+ private String runtimeName;
+
+ private EPServiceProvider epService;
+
+ private Map<String, StreamInput> inputStreams = new ConcurrentHashMap<String, StreamInput>();
+ private Map<String, StreamOutput> outputStreams = new ConcurrentHashMap<String, StreamOutput>();
+
+ private Map<String, ProcessingStatement> statements = new ConcurrentHashMap<String, ProcessingStatement>();
+
+ public EsperRuntimeImpl(String name, URL config)
+ {
+ this.runtimeName = name;
+ Configuration configuration = new Configuration();
+ configuration.configure( config );
+ this.epService = EPServiceProviderManager.getProvider(name, configuration);
+
+ /*epService.getEPRuntime().setUnmatchedListener(
+ new UnmatchedListener()
+ {
+
+ public void update(EventBean event)
+ {
+ System.out.println("! Unmatched: " + event);
+ }
+ }
+ );*/
+ }
+
+ public void addInput(StreamInput streamInput)
+ {
+ streamInput.registerCallback(this);
+ this.inputStreams.put(streamInput.getStreamName(), streamInput);
+ }
+
+ public void removeInput(String streamName)
+ {
+ this.inputStreams.remove(streamName);
+ }
+
+ public Iterator<String> getStreamInputNames()
+ {
+ return this.inputStreams.keySet().iterator();
+ }
+
+ public void addOutput(StreamOutput streamOutput)
+ {
+ this.outputStreams.put(streamOutput.getStreamName(), streamOutput);
+ }
+
+ public void removeOutput(String streamName)
+ {
+ this.outputStreams.remove(streamName);
+ }
+
+ public Iterator<String> getStreamOutputNames()
+ {
+ return this.outputStreams.keySet().iterator();
+ }
+
+ /**
+ * Any event send to an stream goes to the EPRuntime
+ * @param args
+ */
+ public void onEvent(Object args)
+ {
+ epService.getEPRuntime().sendEvent(args);
+ }
+
+ public ProcessingStatement registerStatement(String statementName, String epl)
+ {
+ EPStatement epStatement = epService.getEPAdministrator().createEPL(epl, statementName);
+ return new EsperProcessingStatement(epStatement);
+ }
+
+ public ProcessingStatement registerBoundStatement(String outputStreamName, String statementName, String epl)
+ {
+ StreamOutput streamOutput = this.outputStreams.get(outputStreamName);
+ if(null == streamOutput)
+ throw new IllegalArgumentException("No such output stream: " + outputStreamName);
+
+ EPStatement epStatement = epService.getEPAdministrator().createEPL(epl, statementName);
+ EsperProcessingStatement statement = new EsperProcessingStatement(epStatement);
+ StreamOutputAdapter adapter = new StreamOutputAdapter(streamOutput);
+ statement.getUnderlying().addListener(adapter);
+ return statement;
+ }
+
+ public Iterator<String> getStatementNames()
+ {
+ return this.statements.keySet().iterator();
+ }
+
+
+ public void clearStatement(String statementName)
+ {
+ ProcessingStatement stmt = statements.get(statementName);
+ if(null==stmt)
+ throw new IllegalArgumentException("No such statement: " + statementName);
+
+ statements.remove(statementName);
+ }
+
+ public void clearAllStatements()
+ {
+ Iterator<String> stmtNames = getStatementNames();
+ while(stmtNames.hasNext())
+ {
+ clearStatement(stmtNames.next());
+ }
+ }
+
+ public String getName()
+ {
+ return this.runtimeName;
+ }
+
+ public EPServiceProvider getUnderlying()
+ {
+ return this.epService;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EsperRuntimeImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EventAdapter.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EventAdapter.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EventAdapter.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.esper;
+
+import com.espertech.esper.event.EventBean;
+import org.jboss.sam.EventMessage;
+
+import java.util.Iterator;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class EventAdapter implements EventMessage<EventBean>
+{
+ private final EventBean delegate;
+
+ private long timestamp;
+
+ /**
+ * Create with an implicit timestamp
+ *
+ * @param delegate
+ */
+ public EventAdapter(EventBean delegate)
+ {
+ this.delegate = delegate;
+ this.timestamp = System.currentTimeMillis();
+ }
+
+ /**
+ * Create with an external timestamp
+ * @param delegate
+ * @param timestamp
+ */
+ public EventAdapter(EventBean delegate, long timestamp)
+ {
+ this.delegate = delegate;
+ this.timestamp = timestamp;
+ }
+
+ public long getTimestamp()
+ {
+ return this.timestamp;
+ }
+
+ public Iterator<String> getPropertyNames()
+ {
+ Iterator<String> it = new Iterator<String>()
+ {
+
+ private String[] names = delegate.getEventType().getPropertyNames();
+ private int index=0;
+
+ public boolean hasNext()
+ {
+ return names.length>0 && index<names.length-1;
+ }
+
+ public String next()
+ {
+ String next = names[index];
+ index++;
+ return next;
+ }
+
+ public void remove()
+ {
+ throw new IllegalArgumentException("Not implemented");
+ }
+ };
+
+ return it;
+ }
+
+ public Object getProperty(String property)
+ {
+ return delegate.get(property);
+ }
+
+ public EventBean getUnderlying()
+ {
+ return delegate;
+ }
+
+
+ public String toString()
+ {
+ return "EventAdapter {"+delegate.toString()+"}";
+ }
+}
+
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/EventAdapter.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/StreamOutputAdapter.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/StreamOutputAdapter.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/StreamOutputAdapter.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.esper;
+
+import com.espertech.esper.client.UpdateListener;
+import com.espertech.esper.event.EventBean;
+import org.jboss.sam.EventMessage;
+import org.jboss.sam.StreamOutput;
+
+/**
+ * Adopts an Esper {@link com.espertech.esper.client.UpdateListener}
+ * to to an FX {@link org.jboss.sam.StreamOutput}
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+class StreamOutputAdapter implements UpdateListener
+{
+ protected StreamOutput delegate;
+
+ public StreamOutputAdapter(StreamOutput eventListener)
+ {
+ this.delegate = eventListener;
+ }
+
+ public void update(EventBean[] newEvents, EventBean[] oldEvents)
+ {
+ EventMessage[] args1 = adoptPayload(newEvents);
+ EventMessage[] args2 = adoptPayload(oldEvents);
+
+ // TODO: review StreamOutput interface wrt oldEvents
+
+ delegate.write(args1);
+ }
+
+ private EventMessage[] adoptPayload(EventBean[] data)
+ {
+ int size = data !=null ? data.length : 0;
+ EventMessage[] payloads = new EventMessage[size];
+
+ for(int i=0; i<size; i++)
+ {
+ payloads[i] = new EventAdapter(data[i]);
+ }
+
+ return payloads;
+ }
+
+ StreamOutput getUnderlying()
+ {
+ return this.delegate;
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/esper/StreamOutputAdapter.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMDispatcher.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMDispatcher.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMDispatcher.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.stream;
+
+import org.jboss.sam.StreamInputCallback;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class InVMDispatcher
+{
+ public final static String DEFAULT_CHANNEL_NAME = "InVM-Channel";
+
+ private InVMStreamRegistry channelRegistry;
+
+ private String streamName;
+
+ public InVMDispatcher(String streamName)
+ {
+ this.streamName = streamName;
+ this.channelRegistry = InVMStreamRegistry.getInstance();
+ }
+
+ public void dispatch(Object event)
+ {
+ for(StreamInputCallback callback : channelRegistry.getChannelCallbacks(streamName))
+ {
+ callback.onEvent(event);
+ }
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMDispatcher.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamInput.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamInput.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamInput.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.stream;
+
+import org.jboss.sam.StreamInput;
+import org.jboss.sam.StreamInputCallback;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class InVMStreamInput implements StreamInput
+{
+ private boolean started;
+
+ private String streamName;
+
+ InVMStreamRegistry channelRegistry;
+
+ public InVMStreamInput(String name)
+ {
+ this.streamName = name;
+ this.channelRegistry = InVMStreamRegistry.getInstance();
+ }
+
+ public StreamInput start()
+ {
+ this.started = true;
+ return this;
+ }
+
+ public StreamInput stop()
+ {
+ this.started = false;
+ return this;
+ }
+
+ public boolean isStarted()
+ {
+ return this.started;
+ }
+
+ public String getStreamName()
+ {
+ return this.streamName;
+ }
+
+ public void registerCallback(StreamInputCallback listener)
+ {
+ channelRegistry.getChannelCallbacks(streamName).add(listener);
+ }
+
+ public void clearCallbacks()
+ {
+ channelRegistry.getChannelCallbacks(streamName).clear();
+ }
+
+ public void newEvent(Object args)
+ {
+ for(StreamInputCallback callback : channelRegistry.getChannelCallbacks(streamName))
+ {
+ callback.onEvent(args);
+ }
+
+ }
+
+ public String toString()
+ {
+ return "InVMInputAdapter{"+this.streamName +"}";
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamInput.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamRegistry.java
===================================================================
--- sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamRegistry.java (rev 0)
+++ sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamRegistry.java 2008-07-16 10:46:26 UTC (rev 173)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.sam.internal.stream;
+
+import org.jboss.sam.StreamInputCallback;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class InVMStreamRegistry
+{
+ private Map<String, List<StreamInputCallback>> streams = new ConcurrentHashMap<String, List<StreamInputCallback>>();
+
+ private static InVMStreamRegistry INSTANCE;
+
+ private InVMStreamRegistry()
+ {
+ }
+
+ public static InVMStreamRegistry getInstance()
+ {
+ if(null == INSTANCE)
+ INSTANCE = new InVMStreamRegistry();
+ return INSTANCE;
+ }
+
+ public List<StreamInputCallback> getChannelCallbacks(String streamName)
+ {
+ if(null == streams.get(streamName))
+ streams.put(streamName, new CopyOnWriteArrayList<StreamInputCallback>());
+ return streams.get(streamName);
+ }
+}
Property changes on: sam/trunk/modules/core/src/main/java/org/jboss/sam/internal/stream/InVMStreamRegistry.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the overlord-commits
mailing list