Home | History | Annotate | Download | only in module
      1  239  stephen /*
      2  239  stephen  * CDDL HEADER START
      3  239  stephen  *
      4  239  stephen  * The contents of this file are subject to the terms of the
      5  239  stephen  * Common Development and Distribution License (the "License").
      6  239  stephen  * You may not use this file except in compliance with the License.
      7  239  stephen  *
      8  239  stephen  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  239  stephen  * or http://www.opensolaris.org/os/licensing.
     10  239  stephen  * See the License for the specific language governing permissions
     11  239  stephen  * and limitations under the License.
     12  239  stephen  *
     13  239  stephen  * When distributing Covered Code, include this CDDL HEADER in each
     14  239  stephen  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  239  stephen  * If applicable, add the following below this CDDL HEADER, with the
     16  239  stephen  * fields enclosed by brackets "[]" replaced with your own identifying
     17  239  stephen  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  239  stephen  *
     19  239  stephen  * CDDL HEADER END
     20  239  stephen  */
     21  239  stephen 
     22  239  stephen /*
     23  239  stephen  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     24  239  stephen  * Use is subject to license terms.
     25  239  stephen  */
     26  239  stephen 
     27  239  stephen package org.opensolaris.os.vp.panels.example.time2.server.module;
     28  239  stephen 
     29  239  stephen import java.io.IOException;
     30  239  stephen import java.text.*;
     31  239  stephen import java.util.Date;
     32  239  stephen import javax.management.*;
     33  239  stephen import org.opensolaris.os.vp.panels.example.time2.common.*;
     34  239  stephen import org.opensolaris.os.vp.util.misc.ProcessUtil;
     35  239  stephen import org.opensolaris.os.vp.util.misc.exception.CommandFailedException;
     36  239  stephen 
     37  239  stephen public class Time implements TimeMXBean, MBeanRegistration {
     38  239  stephen     //
     39  239  stephen     // MBeanRegistration methods
     40  239  stephen     //
     41  239  stephen 
     42  239  stephen     @Override
     43  239  stephen     public void postDeregister() {
     44  239  stephen     }
     45  239  stephen 
     46  239  stephen     @Override
     47  239  stephen     public void postRegister(Boolean registrationDone) {
     48  239  stephen     }
     49  239  stephen 
     50  239  stephen     @Override
     51  239  stephen     public void preDeregister() {
     52  239  stephen     }
     53  239  stephen 
     54  239  stephen     @Override
     55  239  stephen     public ObjectName preRegister(MBeanServer server, ObjectName name) {
     56  239  stephen 	if (name == null) {
     57  239  stephen 	    name = TimeUtil.OBJECT_NAME;
     58  239  stephen 	}
     59  239  stephen 	return name;
     60  239  stephen     }
     61  239  stephen 
     62  239  stephen     //
     63  239  stephen     // TimeMXBean methods
     64  239  stephen     //
     65  239  stephen 
     66  239  stephen     @Override
     67  239  stephen     public long getTime() {
     68  239  stephen 	return System.currentTimeMillis();
     69  239  stephen     }
     70  239  stephen 
     71  239  stephen     @Override
     72  239  stephen     public void setTime(long millis) throws IOException {
     73  239  stephen 	Date date = new Date(millis);
     74  239  stephen 	DateFormat format = new SimpleDateFormat("MMddHHmmyyyy.ss");
     75  239  stephen 	String dateString = format.format(date);
     76  239  stephen 
     77  239  stephen 	try {
     78  239  stephen 	    ProcessUtil.exec(0, "/usr/bin/date", dateString);
     79  239  stephen 
     80  239  stephen 	} catch (CommandFailedException e) {
     81  239  stephen 	    throw new IOException(e);
     82  239  stephen 
     83  239  stephen 	// Not likely
     84  239  stephen 	} catch (InterruptedException e) {
     85  239  stephen 	    throw new IOException("command interrupted");
     86  239  stephen 	}
     87  239  stephen     }
     88  239  stephen }
     89