All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.fedora.server.utilities.MethodInvokerThread Maven / Gradle / Ivy

/*
 * -----------------------------------------------------------------------------
 *
 * 

License and Copyright: The contents of this file are subject to the * Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at * http://www.fedora-commons.org/licenses.

* *

Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License.

* *

The entire file consists of original code.

*

Copyright © 2008 Fedora Commons, Inc.
*

Copyright © 2002-2007 The Rector and Visitors of the University of * Virginia and Cornell University
* All rights reserved.

* * ----------------------------------------------------------------------------- */ package fedora.server.utilities; import java.lang.reflect.Method; /** * *

Title: MethodInvokerThread.java

*

Description: A Thread that invokes a single method, * then exits.

* *

This is convenient in situations where some method should run in a separate * Thread, but it is either inconvenient or inappropriate to * write a Runnable to do the work.

* * @author [email protected] * @version $Id: MethodInvokerThread.java 3966 2005-04-21 13:33:01Z rlw $ */ public class MethodInvokerThread extends Thread { /** The object in which the method should be invoked. */ private Object m_object; /** The method. */ private Method m_method; /** The arguments to the method. */ private Object[] m_args; /** The Object returned by the method call, if any. */ private Object m_returned; /** The Throwable the method call resulted in, if any. */ private Throwable m_thrown; /** * Constructs a MethodInvokerThread. * * @param targetObject The object in which the method resides. * @param method The Method to invoke. * @param args The arguments to the method. */ public MethodInvokerThread(Object targetObject, Method method, Object[] args) { m_object=targetObject; m_method=method; m_args=args; } /** * Constructs a MethodInvokerThread with a name. * * @param targetObject The object in which the method resides. * @param method The Method to invoke. * @param args The arguments to the method. * @param name The thread's name. */ public MethodInvokerThread(Object targetObject, Method method, Object[] args, String name) { super(name); m_object=targetObject; m_method=method; m_args=args; } /** * Constructs a MethodInvokerThread with a * ThreadGroup and a name. * * @param targetObject The object in which the method resides. * @param method The Method to invoke. * @param args The arguments to the method. * @param threadGroup The ThreadGroup to which the thread * should belong. * @param name The thread's name. */ public MethodInvokerThread(Object targetObject, Method method, Object[] args, ThreadGroup threadGroup, String name) { super(threadGroup, name); m_object=targetObject; m_method=method; m_args=args; } /** * Invokes the Method, then exits. */ public void run() { try { m_returned=m_method.invoke(m_object, m_args); } catch (Throwable thrown) { m_thrown=thrown; } } /** * Gets the Object returned by the invoked Method. * * @return The Object, or null if the method has no return type or the * method hasn't been invoked yet. */ public Object getReturned() { return m_returned; } /** * Gets the Throwable that resulted if an error occurred while * trying to invoke the Method. * * @return The Throwable, or null if the method's invocation did not * produce a Throwable or the method hasn't been invoked yet. */ public Throwable getThrown() { return m_thrown; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy