KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > ondemand > ServerEntryListenerImpl


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.server.ondemand;
25
26 import java.util.*;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29 import com.sun.logging.LogDomains;
30
31 import com.sun.enterprise.server.ondemand.entry.*;
32
33 /**
34  * Concrete implementation of ServerEntryListener. This directs the
35  * entry to servicegroups.
36  *
37  * @author Binod PG
38  * @see ServiceGroup
39  */

40 public class ServerEntryListenerImpl implements ServerEntryListener {
41
42     private OnDemandServer server = null;
43     private ArrayList listeners = new ArrayList();
44
45     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
46     
47     public ServerEntryListenerImpl(OnDemandServer server) {
48         this.server = server;
49     }
50
51     /**
52      * If atleast one servicegroup that need to be started is interested
53      * in the entry context, return false. Otherwise return true.
54      */

55     public boolean isNotified(EntryContext context) {
56         context.setServerContext(server.getServerContext());
57         return this.server.getServiceGroup().isNotified(context);
58     }
59
60     /**
61      * Notify the main servicegroup about the server entry. If ondemand
62      * initialization is switched off, no entry event (other than the
63      * one special STARTUP event) will be processed.
64      */

65     public void notifyEntry(EntryContext context) {
66         if (server.isOnDemandOff() == true &&
67             context.getEntryPointType() != EntryPoint.STARTUP) {
68             return;
69         }
70         context.setServerContext(server.getServerContext());
71         try {
72             this.server.getServiceGroup().start(context);
73         } catch (Exception JavaDoc e) {
74             _logger.log(Level.SEVERE, e.getMessage(), e);
75         }
76
77         Iterator it = listeners.iterator();
78         while (it.hasNext()) {
79             ServerEntryListener listener = (ServerEntryListener) it.next();
80             listener.notifyEntry(context);
81         }
82     }
83
84     /**
85      * If some other part of the code want to listen to the events this is
86      * a helper methods that can be used to add a listener.
87      */

88     public void addServerEntryListener(ServerEntryListener listener) {
89         listeners.add(listener);
90     }
91
92     /**
93      * Remove a listener from the list.
94      */

95     public void removeServerEntryListener(ServerEntryListener listener) {
96         listeners.remove(listener);
97     }
98 }
99
Popular Tags