1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 package org.opensolaris.os.vp.panels.example.time2.server.module; 28 29 import com.sun.cacao.*; 30 import com.sun.cacao.element.*; 31 import java.util.logging.*; 32 import javax.management.ObjectName; 33 import org.opensolaris.os.vp.panels.example.time2.common.TimeMXBean; 34 import org.opensolaris.os.vp.util.misc.TextUtil; 35 36 public class TimeModule extends Module { 37 // 38 // Instance data 39 // 40 41 private TimeMXBean bean; 42 private ObjectName name; 43 protected final Logger logger; 44 protected final String LOGTAG; 45 46 // 47 // Constructors 48 // 49 50 public TimeModule(DeploymentDescriptor descriptor) { 51 super(descriptor); 52 bean = new Time(); 53 54 Class<? extends TimeModule> c = getClass(); 55 logger = Logger.getLogger(c.getPackage().getName()); 56 LOGTAG = TextUtil.getBaseName(c); 57 } 58 59 // 60 // ElementSupport methods 61 // 62 63 @Override 64 protected void start() { 65 logger.entering(LOGTAG, "start"); 66 67 try { 68 name = getMbs().registerMBean(bean, null).getObjectName(); 69 } catch (Exception e) { 70 logger.log(Level.WARNING, "error during start", e); 71 availabilityStatusSetAdd(AvailabilityStatusEnum.FAILED); 72 setOperationalState(OperationalStateEnum.DISABLED); 73 } 74 75 logger.exiting(LOGTAG, "start"); 76 } 77 78 @Override 79 protected void stop() { 80 logger.entering(LOGTAG, "stop"); 81 82 try { 83 getMbs().unregisterMBean(name); 84 } catch (Exception e) { 85 } 86 87 logger.exiting(LOGTAG, "stop"); 88 } 89 } 90