KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > work > OneWork


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.connectors.work;
25
26 import javax.resource.spi.work.ExecutionContext JavaDoc;
27 import javax.resource.spi.work.Work JavaDoc;
28 import javax.resource.spi.work.WorkListener JavaDoc;
29 import java.util.logging.*;
30 import com.sun.logging.LogDomains;
31
32 /**
33  * Represents one piece of work that will be submitted to the workqueue.
34  *
35  * @author Binod P.G
36  */

37 public class OneWork implements com.sun.corba.ee.spi.orbutil.threadpool.Work {
38
39     private Work JavaDoc work;
40     private WorkCoordinator coordinator;
41     private long nqTime;
42     private static Logger logger =
43         LogDomains.getLogger(LogDomains.RSR_LOGGER);
44
45     /**
46      * Creates a work object that can be submitted to a workqueue.
47      *
48      * @param work Actual work submitted by Resource adapter.
49      * @param coordinator <code>WorkCoordinator</code> object.
50      */

51     OneWork (Work JavaDoc work, WorkCoordinator coordinator) {
52         this.work = work;
53         this.coordinator = coordinator;
54     }
55     
56     /**
57      * This method is executed by thread pool as the basic work operation.
58      */

59     public void doWork() {
60         coordinator.preInvoke();
61         if (coordinator.proceed()) {
62             try {
63                 work.run();
64             } catch (Throwable JavaDoc t) {
65                 coordinator.setException(t);
66             }
67         }
68         coordinator.postInvoke();
69     }
70     
71     /**
72      * Time at which this work is enqueued.
73      *
74      * @param tme Time in milliseconds.
75      */

76     public void setEnqueueTime(long tme) {
77         this.nqTime = tme;
78     }
79
80     /**
81      * Retrieves the time at which this work is enqueued
82      *
83      * @return Time in milliseconds.
84      */

85     public long getEnqueueTime() {
86         return nqTime;
87     }
88
89     /**
90      * Retrieves the name of the work.
91      *
92      * @return Name of the work.
93      */

94     public String JavaDoc getName() {
95         return "Resource adapter work";
96     }
97
98     /**
99      * Retrieves the string representation of work.
100      *
101      * @return String representation of work.
102      */

103     public String JavaDoc toString () {
104         return (work.toString());
105     }
106 }
107
Popular Tags