2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A *
2N/A * ident "%Z%%M% %I% %E% SMI"
2N/A */
2N/Apackage org.opensolaris.os.dtrace;
2N/A
2N/Aimport java.util.*;
2N/Aimport java.io.*;
2N/Aimport java.beans.*;
2N/A
2N/A/**
2N/A * A {@link ProbeDescription} identifying a single probe combined with
2N/A * information about the identified probe.
2N/A * <p>
2N/A * Immutable. Supports persistence using {@link java.beans.XMLEncoder}.
2N/A *
2N/A * @see Consumer#listProbes(ProbeDescription filter)
2N/A * @see Consumer#listProgramProbes(Program program)
2N/A *
2N/A * @author Tom Erickson
2N/A */
2N/Apublic final class Probe implements Serializable {
2N/A static final long serialVersionUID = 8917481979541675727L;
2N/A
2N/A static {
2N/A try {
2N/A BeanInfo info = Introspector.getBeanInfo(Probe.class);
2N/A PersistenceDelegate persistenceDelegate =
2N/A new DefaultPersistenceDelegate(
2N/A new String[] {"description", "info"})
2N/A {
2N/A /*
2N/A * Need to prevent DefaultPersistenceDelegate from using
2N/A * overridden equals() method, resulting in a
2N/A * StackOverFlowError. Revert to PersistenceDelegate
2N/A * implementation. See
2N/A * http://forum.java.sun.com/thread.jspa?threadID=
2N/A * 477019&tstart=135
2N/A */
2N/A protected boolean
2N/A mutatesTo(Object oldInstance, Object newInstance)
2N/A {
2N/A return (newInstance != null && oldInstance != null &&
2N/A oldInstance.getClass() == newInstance.getClass());
2N/A }
2N/A };
2N/A BeanDescriptor d = info.getBeanDescriptor();
2N/A d.setValue("persistenceDelegate", persistenceDelegate);
2N/A } catch (IntrospectionException e) {
2N/A System.out.println(e);
2N/A }
2N/A }
2N/A
2N/A /** @serial */
2N/A private final ProbeDescription description;
2N/A /** @serial */
2N/A private final ProbeInfo info;
2N/A
2N/A /**
2N/A * Creates a {@code Probe} instance with the given identifying
2N/A * description and associated probe information. Supports XML
2N/A * persistence.
2N/A *
2N/A * @param probeDescription probe description that identifies a
2N/A * single DTrace probe
2N/A * @param probeInfo information about the identified probe, {@code
2N/A * null} indicating that the information could not be obtained
2N/A * @throws NullPointerException if the given probe description is
2N/A * {@code null}
2N/A */
2N/A public
2N/A Probe(ProbeDescription probeDescription, ProbeInfo probeInfo)
2N/A {
2N/A description = probeDescription;
2N/A info = probeInfo;
2N/A validate();
2N/A }
2N/A
2N/A private final void
2N/A validate()
2N/A {
2N/A if (description == null) {
2N/A throw new NullPointerException("description is null");
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Gets the probe description identifying a single probe described
2N/A * by this instance.
2N/A *
2N/A * @return non-null probe description matching a single probe on the
2N/A * system
2N/A */
2N/A public ProbeDescription
2N/A getDescription()
2N/A {
2N/A return description;
2N/A }
2N/A
2N/A /**
2N/A * Gets information including attributes and argument types of the
2N/A * probe identified by {@link #getDescription()}.
2N/A *
2N/A * @return information about the probe identified by {@link
2N/A * #getDescription()}, or {@code null} if that information could not
2N/A * be obtained for any reason
2N/A */
2N/A public ProbeInfo
2N/A getInfo()
2N/A {
2N/A return info;
2N/A }
2N/A
2N/A /**
2N/A * Compares the specified object with this {@code Probe} instance
2N/A * for equality. Defines equality as having the same probe
2N/A * description.
2N/A *
2N/A * @return {@code true} if and only if the specified object is also
2N/A * a {@code Probe} and both instances return equal values from
2N/A * {@link #getDescription()}.
2N/A */
2N/A @Override
2N/A public boolean
2N/A equals(Object o)
2N/A {
2N/A if (o instanceof Probe) {
2N/A Probe p = (Probe)o;
2N/A return description.equals(p.description);
2N/A }
2N/A return false;
2N/A }
2N/A
2N/A /**
2N/A * Overridden to ensure that equal instances have equal hash codes.
2N/A */
2N/A @Override
2N/A public int
2N/A hashCode()
2N/A {
2N/A return description.hashCode();
2N/A }
2N/A
2N/A private void
2N/A readObject(ObjectInputStream s)
2N/A throws IOException, ClassNotFoundException
2N/A {
2N/A s.defaultReadObject();
2N/A // Check class invariants
2N/A try {
2N/A validate();
2N/A } catch (Exception e) {
2N/A InvalidObjectException x = new InvalidObjectException(
2N/A e.getMessage());
2N/A x.initCause(e);
2N/A throw x;
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Returns a string representation of this {@code Probe} useful for
2N/A * logging and not intended for display. The exact details of the
2N/A * representation are unspecified and subject to change, but the
2N/A * following format may be regarded as typical:
2N/A * <pre><code>
2N/A * class-name[property1 = value1, property2 = value2]
2N/A * </code></pre>
2N/A */
2N/A public String
2N/A toString()
2N/A {
2N/A StringBuilder buf = new StringBuilder();
2N/A buf.append(Probe.class.getName());
2N/A buf.append("[description = ");
2N/A buf.append(description);
2N/A buf.append(", info = ");
2N/A buf.append(info);
2N/A buf.append(']');
2N/A return buf.toString();
2N/A }
2N/A}