/* * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package sun.jvmstat.perfdata.monitor.protocol.rmi; import sun.jvmstat.monitor.*; import sun.jvmstat.monitor.event.*; import sun.jvmstat.monitor.remote.*; import sun.jvmstat.perfdata.monitor.*; import java.lang.reflect.*; import java.util.*; import java.io.*; import java.nio.ByteBuffer; import java.rmi.*; /** * Concrete implementation of the AbstractMonitoredVm class for the * rmi: protocol for the HotSpot PerfData monitoring implementation. *
* This class provides the ability to acquire to the instrumentation buffer
* of a live, remote target Java Virtual Machine through an RMI server.
*
* @author Brian Doherty
* @since 1.5
*/
public class RemoteMonitoredVm extends AbstractMonitoredVm {
private ArrayList
* The data in the remote instrumentation buffer is copied into
* a local byte buffer.
*
* @throws RemoteException Thrown on any communications errors with
* the remote system.
*/
public void sample() throws RemoteException {
assert updateBuffer != null;
((PerfDataBuffer)pdb).sample(updateBuffer);
}
/**
* Get the proxy to the remote MonitoredVm.
*
* @return RemoteVm - the proxy to the remote MonitoredVm.
*/
public RemoteVm getRemoteVm() {
return rvm;
}
/**
* {@inheritDoc}
*/
public void addVmListener(VmListener l) {
synchronized(listeners) {
listeners.add(l);
if (notifierTask == null) {
notifierTask = new NotifierTask();
timer.schedule(notifierTask, 0, interval);
}
}
}
/**
* {@inheritDoc}
*/
public void removeVmListener(VmListener l) {
synchronized(listeners) {
listeners.remove(l);
if (listeners.isEmpty() && (notifierTask != null)) {
notifierTask.cancel();
notifierTask = null;
}
}
}
/**
* {@inheritDoc}
*/
public void setInterval(int newInterval) {
synchronized(listeners) {
if (newInterval == interval) {
return;
}
int oldInterval = interval;
super.setInterval(newInterval);
if (samplerTask != null) {
samplerTask.cancel();
SamplerTask oldSamplerTask = samplerTask;
samplerTask = new SamplerTask();
CountedTimerTaskUtils.reschedule(timer, oldSamplerTask,
samplerTask, oldInterval,
newInterval);
}
if (notifierTask != null) {
notifierTask.cancel();
NotifierTask oldNotifierTask = notifierTask;
notifierTask = new NotifierTask();
CountedTimerTaskUtils.reschedule(timer, oldNotifierTask,
notifierTask, oldInterval,
newInterval);
}
}
}
/**
* Fire MonitoredVmStructureChanged events.
*
* @param inserted List of Monitor objects inserted.
* @param removed List of Monitor objects removed.
*/
@SuppressWarnings("unchecked") // Cast of result of clone
void fireMonitorStatusChangedEvents(List