KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > spi > distributed > DistributedEJBServiceFactory


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.ejb.spi.distributed;
25
26 import java.io.ByteArrayInputStream JavaDoc;
27 import java.io.ByteArrayOutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.ObjectInputStream JavaDoc;
30 import java.io.ObjectOutputStream JavaDoc;
31 import java.io.Serializable JavaDoc;
32
33 import java.util.logging.Logger JavaDoc;
34 import java.util.logging.Level JavaDoc;
35
36 import com.sun.logging.LogDomains;
37
38 import java.util.concurrent.ConcurrentHashMap JavaDoc;
39
40 public class DistributedEJBServiceFactory
41     implements DistributedEJBService
42 {
43
44     private static Logger JavaDoc _logger =
45         LogDomains.getLogger(LogDomains.EJB_LOGGER);
46     
47     protected static DistributedEJBService distributedEJBService = null;
48     protected static DistributedEJBTimerService distributedEJBTimerService = null;
49
50     private static DistributedReadOnlyBeanService _distributedReadOnlyBeanService
51         = new DistributedReadOnlyBeanServiceImpl();
52     public static DistributedEJBService getDistributedEJBService() {
53         if(distributedEJBService == null) {
54             distributedEJBService = new DistributedEJBServiceFactory();
55         }
56
57         return distributedEJBService;
58     }
59
60     protected DistributedEJBServiceFactory() {
61         distributedEJBService = this;
62     }
63
64
65     public static void setDistributedEJBTimerService(
66         DistributedEJBTimerService distribEJBTimerService ) {
67         
68         getDistributedEJBService();
69
70         //The distributedEJBTimerService is the EJBTimerService that should
71
//be assigned as part of the server startup. Also this code makes sense
72
//in the appserv-core part of the land. But since this method is on the
73
//interface even the appserv-core-ee code might call it. Need to safeguard
74
//against this possibility.
75
if( null == distributedEJBTimerService ) {
76             distributedEJBTimerService = distribEJBTimerService;
77         }
78     }
79
80     /**
81      *--------------------------------------------------------------
82      * Methods to be implemented for DistributedEJBService
83      *--------------------------------------------------------------
84      */

85     public int migrateTimers( String JavaDoc serverId ) {
86         int result = 0;
87         if (distributedEJBTimerService != null) {
88             result = distributedEJBTimerService.migrateTimers( serverId );
89         } else {
90             //throw new IllegalStateException("EJB Timer service is null. "
91
//+ "Cannot migrate timers for: " + serverId);
92
}
93         
94         return result;
95     }
96
97     public String JavaDoc[] listTimers( String JavaDoc[] serverIds ) {
98         String JavaDoc[] result = new String JavaDoc[serverIds.length];
99         if (distributedEJBTimerService != null) {
100             result = distributedEJBTimerService.listTimers( serverIds );
101         } else {
102             //FIXME: Should throw IllegalStateException
103
for (int i=0; i<serverIds.length; i++) {
104                 result[i] = "0";
105             }
106             //throw new com.sun.enterprise.admin.common.exception.AFException("EJB Timer service is null. "
107
//+ "Cannot list timers.");
108
}
109         
110         return result;
111     }
112
113     public void setPerformDBReadBeforeTimeout( boolean defaultDBReadValue ) {
114         if( null != distributedEJBTimerService ) {
115             distributedEJBTimerService.setPerformDBReadBeforeTimeout(
116                                            defaultDBReadValue );
117         } else {
118             // Should we ensure that the EJBTimerService can not be null
119
// in the case of SE/EE
120
}
121     }
122
123     public DistributedReadOnlyBeanService getDistributedReadOnlyBeanService() {
124         return _distributedReadOnlyBeanService;
125     }
126
127 } //DistributedEJBServiceFactory.java
128

129
Popular Tags