com.sun.sgs.impl.profile
Class ProfileCollectorImpl

java.lang.Object
  extended by com.sun.sgs.impl.profile.ProfileCollectorImpl
All Implemented Interfaces:
ProfileCollector

public final class ProfileCollectorImpl
extends Object
implements ProfileCollector

This is the implementation of ProfileCollector used by the kernel to collect and report profiling data. It uses a single thread to consume and report profiling data to ProfileListeners.

The constructor supports the following properties:

Property: com.sun.sgs.impl.profile.create.mbeanserver
Default: false
Specifies whether a new MBeanServer should be created, rather than using the existing platform MBeanServer.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.sun.sgs.profile.ProfileCollector
ProfileCollector.ProfileLevel
 
Field Summary
static String CORE_CONSUMER_PREFIX
          The standard prefix for consumer names created by core packages.
static String CREATE_MBEAN_SERVER_PROPERTY
          The property telling us whether we should use the default platform MBeanServer or create a new one.
 
Constructor Summary
ProfileCollectorImpl(ProfileCollector.ProfileLevel level, Properties appProperties, ComponentRegistry systemRegistry)
          Creates an instance of ProfileCollectorImpl.
 
Method Summary
 void addListener(ProfileListener listener, boolean canRemove)
          Adds a ProfileListener as a listener for profiling data reports.
 void addListener(String listenerClassName)
          Instantiates and adds a ProfileListener.
(package private)  void addParticipant(ProfileParticipantDetail participantDetail)
          Tells the collector about a participant of a transaction when that participant has finished participating (i.e., has committed, has prepared read-only, or has aborted).
(package private)  void addTransactionListener(TransactionListenerDetail listenerDetail)
          Tells the collector about a listener of a transaction when that listener is finished with its work (i.e., after its afterCompletion method has been called).
(package private)  void finishTask(int tryCount)
          Tells the collector that the current task associated with the calling thread (as associated by a call to startTask) has now successfully finished.
(package private)  void finishTask(int tryCount, Throwable t)
          Tells the collector that the current task associated with the calling thread (as associated by a call to startTask) has now finished.
 ProfileConsumer getConsumer(String name)
          Returns the named ProfileConsumer, or creates a new one with that name.
 Map<String,ProfileConsumer> getConsumers()
          Returns a read-only map of ProfileConsumer names to the ProfileConsumers which have been created through a call to getConsumer.
(package private)  ProfileReportImpl getCurrentProfileReport()
          Package private method to get the current profile report, used by the operations, counters, and samples.
 ProfileCollector.ProfileLevel getDefaultProfileLevel()
          Gets the default system profiling level, which is the default level for any newly created ProfileConsumer.
 List<ProfileListener> getListeners()
          Returns a read-only list of ProfileListeners which have been added.
 Object getRegisteredMBean(String mBeanName)
          Returns the object registered under the given name, or null if no object has been registered with that name.
(package private)  void noteTransactional(byte[] txnId)
          Tells the collector that the current task associated with the calling thread (as associated by a call to startTask) is transactional.
(package private)  void notifyListeners(PropertyChangeEvent event)
          Package private method to notify listeners of a property change.
(package private)  void notifyNodeIdAssigned(long nodeId)
          Notifies the collector that the node has been assigned its identifier.
(package private)  void notifyThreadAdded()
          Notifies the collector that a thread has been added to the scheduler.
(package private)  void notifyThreadRemoved()
          Notifies the collector that a thread has been removed from the scheduler.
 void registerMBean(Object mBean, String mBeanName)
          Registers the given MBean with the current VM's platform MBean server, allowing it to be monitored by tools like JConsole.
 void removeListener(ProfileListener listener)
          Removes a ProfileListener and calls ProfileListener.shutdown() on the listener.
(package private)  void setAccessedObjectsDetail(AccessedObjectsDetail detail)
          Sets the detail for all objects accessed during the task as reported to the AccessCoordinator.
 void setDefaultProfileLevel(ProfileCollector.ProfileLevel level)
          Sets the default profile level, used as the initial level when creating new ProfileConsumers.
 void shutdown()
          Shuts down the ProfileCollector, reclaiming resources as necessary.
(package private)  void startTask(KernelRunnable task, Identity owner, long scheduledStartTime, int readyCount)
          Tells the collector that a new task is starting in the context of the calling thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CORE_CONSUMER_PREFIX

public static final String CORE_CONSUMER_PREFIX
The standard prefix for consumer names created by core packages.

See Also:
Constant Field Values

CREATE_MBEAN_SERVER_PROPERTY

public static final String CREATE_MBEAN_SERVER_PROPERTY
The property telling us whether we should use the default platform MBeanServer or create a new one.

See Also:
Constant Field Values
Constructor Detail

ProfileCollectorImpl

public ProfileCollectorImpl(ProfileCollector.ProfileLevel level,
                            Properties appProperties,
                            ComponentRegistry systemRegistry)
Creates an instance of ProfileCollectorImpl.

Parameters:
level - the default system profiling level
appProperties - the application properties, used for instantiating ProfileListeners
systemRegistry - the system registry, used for instantiating ProfileListeners
Method Detail

shutdown

public void shutdown()
Shuts down the ProfileCollector, reclaiming resources as necessary.

Specified by:
shutdown in interface ProfileCollector

getDefaultProfileLevel

public ProfileCollector.ProfileLevel getDefaultProfileLevel()
Gets the default system profiling level, which is the default level for any newly created ProfileConsumer.

Specified by:
getDefaultProfileLevel in interface ProfileCollector
Returns:
the default profiling level

setDefaultProfileLevel

public void setDefaultProfileLevel(ProfileCollector.ProfileLevel level)
Sets the default profile level, used as the initial level when creating new ProfileConsumers.

Specified by:
setDefaultProfileLevel in interface ProfileCollector
Parameters:
level - the new default profile level

getConsumer

public ProfileConsumer getConsumer(String name)
Returns the named ProfileConsumer, or creates a new one with that name.

Note that the name must be unique for a new ProfileConsumer to be created. Consumers created by the core server packages have a prefix of com.sun.sgs. to distinguish their namespace. Consumers created by code outside of the core server packages should create their own unique namespace.

Calling ProfileCollector.getConsumers() will return a map keyed by names already in use.

Specified by:
getConsumer in interface ProfileCollector
Parameters:
name - the unique name of the profile consumer
Returns:
a ProfileConsumer with the given name

getConsumers

public Map<String,ProfileConsumer> getConsumers()
Returns a read-only map of ProfileConsumer names to the ProfileConsumers which have been created through a call to getConsumer.

Specified by:
getConsumers in interface ProfileCollector
Returns:
the map of names to consumers

addListener

public void addListener(ProfileListener listener,
                        boolean canRemove)
Adds a ProfileListener as a listener for profiling data reports. The listener is immediately updated on the current set of operations and the number of scheduler threads. The listener can be marked as unable to be removed by removeListener or shutdown by ProfileCollector.shutdown(); if these operations are performed on a listener that does not allow them, they are silently ignored.

Specified by:
addListener in interface ProfileCollector
Parameters:
listener - the ProfileListener to add
canRemove - true if this listener can be removed or shut down by the ProfileCollector. This parameter should usually be set to true.

addListener

public void addListener(String listenerClassName)
                 throws Exception
Instantiates and adds a ProfileListener. The listener must implement a constructor of the form (java.util.Properties, com.sun.sgs.kernel.TaskOwner, com.sun.sgs.kernel.ComponentRegistry). The listener is immediately updated on the current set of operations and the number of scheduler threads.

Specified by:
addListener in interface ProfileCollector
Parameters:
listenerClassName - the fully qualified class name of the listener to instantiate and add.
Throws:
Exception - if any were generated during instantiation

getListeners

public List<ProfileListener> getListeners()
Returns a read-only list of ProfileListeners which have been added.

Specified by:
getListeners in interface ProfileCollector
Returns:
the list of listeners

removeListener

public void removeListener(ProfileListener listener)
Removes a ProfileListener and calls ProfileListener.shutdown() on the listener. If the listener has never been added with addListener, no action is taken.

Specified by:
removeListener in interface ProfileCollector
Parameters:
listener - the listener to remove

registerMBean

public void registerMBean(Object mBean,
                          String mBeanName)
                   throws JMException
Registers the given MBean with the current VM's platform MBean server, allowing it to be monitored by tools like JConsole.

Specified by:
registerMBean in interface ProfileCollector
Parameters:
mBean - the MBean or MXBean to be registered
mBeanName - the name under which it should be registered
Throws:
JMException - if there were any problems reported by the JMX system during registration, including if an object has already been registered with the mBeanName

getRegisteredMBean

public Object getRegisteredMBean(String mBeanName)
Returns the object registered under the given name, or null if no object has been registered with that name.

Specified by:
getRegisteredMBean in interface ProfileCollector
Parameters:
mBeanName - the name the object was registered under
Returns:
the object passed into registerMBean with the given mBeanName

notifyThreadAdded

void notifyThreadAdded()
Notifies the collector that a thread has been added to the scheduler.


notifyThreadRemoved

void notifyThreadRemoved()
Notifies the collector that a thread has been removed from the scheduler.


notifyNodeIdAssigned

void notifyNodeIdAssigned(long nodeId)
Notifies the collector that the node has been assigned its identifier.


startTask

void startTask(KernelRunnable task,
               Identity owner,
               long scheduledStartTime,
               int readyCount)
Tells the collector that a new task is starting in the context of the calling thread.

Parameters:
task - the KernelRunnable that is starting
owner - the Identity of the task owner
scheduledStartTime - the requested starting time for the task
readyCount - the number of ready tasks at the scheduler

noteTransactional

void noteTransactional(byte[] txnId)
Tells the collector that the current task associated with the calling thread (as associated by a call to startTask) is transactional.

Parameters:
txnId - the identifier for the transaction

addParticipant

void addParticipant(ProfileParticipantDetail participantDetail)
Tells the collector about a participant of a transaction when that participant has finished participating (i.e., has committed, has prepared read-only, or has aborted).

Parameters:
participantDetail - the detail associated with the participant

addTransactionListener

void addTransactionListener(TransactionListenerDetail listenerDetail)
Tells the collector about a listener of a transaction when that listener is finished with its work (i.e., after its afterCompletion method has been called).

Parameters:
listenerDetail - the detail associated with the listener

setAccessedObjectsDetail

void setAccessedObjectsDetail(AccessedObjectsDetail detail)
Sets the detail for all objects accessed during the task as reported to the AccessCoordinator.

Parameters:
detail - all detail of the accessed objects

finishTask

void finishTask(int tryCount)
Tells the collector that the current task associated with the calling thread (as associated by a call to startTask) has now successfully finished.

Parameters:
tryCount - the number of times that the task has tried to run

finishTask

void finishTask(int tryCount,
                Throwable t)
Tells the collector that the current task associated with the calling thread (as associated by a call to startTask) has now finished.

Parameters:
tryCount - the number of times that the task has tried to run
t - the Throwable thrown during task execution

notifyListeners

void notifyListeners(PropertyChangeEvent event)
Package private method to notify listeners of a property change.

Parameters:
event - the change the listeners will be notified about

getCurrentProfileReport

ProfileReportImpl getCurrentProfileReport()
Package private method to get the current profile report, used by the operations, counters, and samples.

Returns:
the thread-local profile report for the currently running task

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved