[jboss-cvs] JBossAS SVN: r62825 - in projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade: asynch and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun May 6 15:11:08 EDT 2007
Author: alesj
Date: 2007-05-06 15:11:08 -0400 (Sun, 06 May 2007)
New Revision: 62825
Added:
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/BundleEventEmitter.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/RunnableEventEmitter.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/RunnableExecutor.java
projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/ThreadPoolExecutor.java
Log:
Asynchronous bundle events initial impl.
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/BundleEventEmitter.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/BundleEventEmitter.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/BundleEventEmitter.java 2007-05-06 19:11:08 UTC (rev 62825)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.osgi.plugins.facade.asynch;
+
+import org.jboss.kernel.spi.event.KernelEvent;
+import org.jboss.kernel.spi.event.KernelEventListener;
+import org.jboss.osgi.plugins.facade.BundleListenerImpl;
+
+/**
+ * Bundle event emitter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BundleEventEmitter extends RunnableEventEmitter
+{
+ public BundleEventEmitter(RunnableExecutor executor)
+ {
+ super(executor);
+ }
+
+ public BundleEventEmitter(RunnableExecutor executor, long startTimeout, long completeTimeout)
+ {
+ super(executor, startTimeout, completeTimeout);
+ }
+
+ protected boolean useRunnable(KernelEventListener listener, KernelEvent event, Object handback)
+ {
+ if (listener instanceof BundleListenerImpl)
+ {
+ BundleListenerImpl bli = (BundleListenerImpl)listener;
+ return bli.isSynchronous() == false;
+ }
+ return false;
+ }
+}
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/RunnableEventEmitter.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/RunnableEventEmitter.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/RunnableEventEmitter.java 2007-05-06 19:11:08 UTC (rev 62825)
@@ -0,0 +1,108 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.osgi.plugins.facade.asynch;
+
+import org.jboss.kernel.plugins.event.AbstractEventEmitter;
+import org.jboss.kernel.spi.event.KernelEvent;
+import org.jboss.kernel.spi.event.KernelEventListener;
+
+/**
+ * Runnable wrapper event emitter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class RunnableEventEmitter extends AbstractEventEmitter
+{
+ protected RunnableExecutor executor;
+ protected long startTimeout;
+ protected long completeTimeout;
+
+ /**
+ * Create new RunnableExecutor with value zero as defaults.
+ *
+ * @param executor the executor
+ */
+ public RunnableEventEmitter(RunnableExecutor executor)
+ {
+ this(executor, 0, 0);
+ }
+
+ /**
+ * Create new RunnableExecutor with default limits.
+ *
+ * @param executor the runnable executor
+ * @param startTimeout default start limit
+ * @param completeTimeout default completion limit
+ */
+ public RunnableEventEmitter(RunnableExecutor executor, long startTimeout, long completeTimeout)
+ {
+ if (executor == null)
+ throw new IllegalArgumentException("Null executor");
+ this.executor = executor;
+ this.startTimeout = startTimeout;
+ this.completeTimeout = completeTimeout;
+ }
+
+ /**
+ * Should we use runnable executor to execute listener call.
+ *
+ * @param listener the listener
+ * @param event the event
+ * @param handback the handback
+ * @return true if we should use runnable, false to use default listener execution
+ */
+ protected boolean useRunnable(KernelEventListener listener, KernelEvent event, Object handback)
+ {
+ return true;
+ }
+
+ protected void fireKernelEvent(KernelEventListener listener, KernelEvent event, Object handback)
+ {
+ if (useRunnable(listener, event, handback))
+ {
+ executor.run(new RunnableWrapper(listener, event, handback), startTimeout, completeTimeout);
+ }
+ else
+ {
+ super.fireKernelEvent(listener, event, handback);
+ }
+ }
+
+ private class RunnableWrapper implements Runnable
+ {
+ private KernelEventListener listener;
+ private KernelEvent event;
+ private Object handback;
+
+ public RunnableWrapper(KernelEventListener listener, KernelEvent event, Object handback)
+ {
+ this.listener = listener;
+ this.event = event;
+ this.handback = handback;
+ }
+
+ public void run()
+ {
+ listener.onEvent(event, handback);
+ }
+ }
+}
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/RunnableExecutor.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/RunnableExecutor.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/RunnableExecutor.java 2007-05-06 19:11:08 UTC (rev 62825)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.osgi.plugins.facade.asynch;
+
+/**
+ * Runnable executor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface RunnableExecutor
+{
+ /**
+ * Run a runnable
+ *
+ * @param runnable the runnable
+ * @throws IllegalArgumentException for a null runnable
+ */
+ void run(Runnable runnable);
+
+ /**
+ * Run runnable within limits.
+ *
+ * @param runnable the runnable
+ * @param startTimeout start limit
+ * @param completeTimeout completion limit
+ * @throws IllegalArgumentException for a null runnable
+ */
+ void run(Runnable runnable, long startTimeout, long completeTimeout);
+}
Added: projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/ThreadPoolExecutor.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/ThreadPoolExecutor.java (rev 0)
+++ projects/microcontainer/trunk/osgi-int/src/main/org/jboss/osgi/plugins/facade/asynch/ThreadPoolExecutor.java 2007-05-06 19:11:08 UTC (rev 62825)
@@ -0,0 +1,52 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.osgi.plugins.facade.asynch;
+
+import org.jboss.util.threadpool.ThreadPool;
+
+/**
+ * JBoss ThreadPool impl RunnableExecutor.
+ * It takes ThreadPool from jboss-common as actual executor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ThreadPoolExecutor implements RunnableExecutor
+{
+ protected ThreadPool threadPool;
+
+ public ThreadPoolExecutor(ThreadPool threadPool)
+ {
+ if (threadPool == null)
+ throw new IllegalArgumentException("Null thread pool");
+ this.threadPool = threadPool;
+ }
+
+ public void run(Runnable runnable)
+ {
+ threadPool.run(runnable);
+ }
+
+ public void run(Runnable runnable, long startTimeout, long completeTimeout)
+ {
+ threadPool.run(runnable, startTimeout, completeTimeout);
+ }
+}
More information about the jboss-cvs-commits
mailing list