KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > selfmanagement > event > LifeCycleImpl


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.admin.selfmanagement.event;
25
26 import javax.management.Notification JavaDoc;
27 import javax.management.NotificationBroadcasterSupport JavaDoc;
28 import javax.management.MBeanNotificationInfo JavaDoc;
29 import com.sun.enterprise.server.ServerContext;
30
31
32
33 /**
34  * LifeCycleImpl is an MBean that implements the LifecycleListener
35  * interface and is a subclass of NotificationBroadcasterSupport.
36  */

37 public class LifeCycleImpl extends NotificationBroadcasterSupport JavaDoc implements LifeCycleImplMBean {
38     
39     public LifeCycleImpl() {
40         DeclarativeLifecycleEventService.setLifeCycleImpl(this);
41     }
42     
43     /**
44      * Notification sequence number within the source object.
45      */

46     private long sequenceNumber = 0;
47     
48     
49     public void onReady(ServerContext sc) {
50         long seqno;
51         synchronized (this) {
52             seqno = sequenceNumber++;
53         }
54         //LifeCycleNotification n = new LifeCycleNotification(LifeCycleNotification.READY_EVENT, this, seqno, "Ready!!!");
55
Notification JavaDoc n = new Notification JavaDoc(LifeCycleEvent.READY_EVENT, this, seqno, "Ready!!!");
56         sendNotification(n);
57         
58     }
59     
60     public void onShutdown() {
61         long seqno;
62         synchronized (this) {
63             seqno = sequenceNumber++;
64         }
65         //LifeCycleNotification n = new LifeCycleNotification(LifeCycleNotification.SHUTDOWN_EVENT, this, seqno, "Shutting Down!!!");
66
Notification JavaDoc n = new Notification JavaDoc(LifeCycleEvent.SHUTDOWN_EVENT, this, seqno, "Shutting Down!!!");
67     sendNotification(n);
68         
69     }
70     
71     public void onTermination() {
72         long seqno;
73         synchronized (this) {
74             seqno = sequenceNumber++;
75         }
76         //LifeCycleNotification n = new LifeCycleNotification(LifeCycleNotification.TERMINATION_EVENT, this, seqno, "Terminated!!!");
77
Notification JavaDoc n = new Notification JavaDoc(LifeCycleEvent.TERMINATION_EVENT, this, seqno, "Terminated!!!");
78         sendNotification(n);
79         
80     }
81     
82     
83     public MBeanNotificationInfo JavaDoc[] getNotificationInfo() {
84         return notifsInfo;
85     }
86     
87     private static final String JavaDoc[] types = {
88         LifeCycleEvent.READY_EVENT,
89                 LifeCycleEvent.SHUTDOWN_EVENT,
90                 LifeCycleEvent.TERMINATION_EVENT
91     };
92     
93     
94     private static final MBeanNotificationInfo JavaDoc[] notifsInfo = {
95         new MBeanNotificationInfo JavaDoc(
96                 types,
97                 "javax.management.Notification",
98                 "Notifications sent by the LifeCycleImpl MBean")
99     };
100     
101     
102 }
103
Popular Tags