[jboss-svn-commits] JBoss Common SVN: r4171 - invokablecontainer/trunk/api/src/main/java/org/jboss/invokable.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Mar 11 12:20:42 EST 2010
Author: david.lloyd at jboss.com
Date: 2010-03-11 12:20:41 -0500 (Thu, 11 Mar 2010)
New Revision: 4171
Added:
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/InvocationProcessor.java
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ProcessingInvocationDispatcher.java
Log:
Since InvocationDispatcher now identifies the target uniquely, reintroduce InvocationProcessor so that long interceptor chains need not be duplicated for every instance.
Added: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/InvocationProcessor.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/InvocationProcessor.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/InvocationProcessor.java 2010-03-11 17:20:41 UTC (rev 4171)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.invokable;
+
+/**
+ * A processor for invocations. May perform some action, including but not limited to handling the invocation, before
+ * or in lieu of passing it on to the dispatcher or another processor.
+ *
+ * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ */
+public interface InvocationProcessor {
+
+ /**
+ * Process an invocation.
+ *
+ * @param dispatcher the dispatcher which is expected to handle this invocation
+ * @param invocation the invocation
+ * @return the result of the invocation
+ * @throws InvocationException If the underlying invocation resulted in some Exception; the original exception may be
+ * obtained via {@link InvocationException#getCause()}
+ * @throws IllegalArgumentException If the invocation or dispatcher is not specified (i.e. {@code null})
+ */
+ Object processInvocation(InvocationDispatcher dispatcher, Invocation invocation) throws InvocationException, IllegalArgumentException;
+
+ /**
+ * A simple dispatching invocation processor, used typically at the end of an interceptor chain.
+ */
+ InvocationProcessor DISPATCHING = new InvocationProcessor() {
+ public Object processInvocation(final InvocationDispatcher dispatcher, final Invocation invocation) throws InvocationException {
+ return dispatcher.dispatch(invocation);
+ }
+ };
+}
Added: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ProcessingInvocationDispatcher.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ProcessingInvocationDispatcher.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ProcessingInvocationDispatcher.java 2010-03-11 17:20:41 UTC (rev 4171)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.invokable;
+
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+/**
+ * An invocation dispatcher which passes an invocation through a processor.
+ *
+ * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ */
+public final class ProcessingInvocationDispatcher implements InvocationDispatcher, Serializable {
+
+ private static final long serialVersionUID = 7824671204114779296L;
+
+ /**
+ * The invocation dispatcher to pass in to the processor.
+ *
+ * @serial
+ */
+ private final InvocationDispatcher dispatcher;
+ /**
+ * The invocation processor to delegate to.
+ *
+ * @serial
+ */
+ private final InvocationProcessor processor;
+
+ /**
+ * Create a new instance.
+ *
+ * @param dispatcher the invocation dispatcher
+ * @param processor the invocation processor
+ */
+ public ProcessingInvocationDispatcher(final InvocationDispatcher dispatcher, final InvocationProcessor processor) throws IllegalArgumentException {
+ if (dispatcher == null) {
+ throw new IllegalArgumentException("dispatcher is null");
+ }
+ if (processor == null) {
+ throw new IllegalArgumentException("processor is null");
+ }
+ this.dispatcher = dispatcher;
+ this.processor = processor;
+ }
+
+ /** {@inheritDoc} This implementation passes the invocation through its processor. */
+ public Object dispatch(final Invocation invocation) throws InvocationException {
+ return processor.processInvocation(dispatcher, invocation);
+ }
+
+ private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ if (dispatcher == null) {
+ throw new InvalidObjectException("dispatcher is null");
+ }
+ if (processor == null) {
+ throw new InvalidObjectException("processor is null");
+ }
+ final SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ if (! dispatcher.getClass().getProtectionDomain().implies(InvocationPermission.INVOKE)) {
+ throw new InvalidObjectException("Dispatcher does not have invoke permission");
+ }
+ if (! processor.getClass().getProtectionDomain().implies(InvocationPermission.INVOKE)) {
+ throw new InvalidObjectException("Processor does not have invoke permission");
+ }
+ }
+ }
+}
More information about the jboss-svn-commits
mailing list