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 * Probe stability information. Does not identify a probe, but gives
2N/A * information about a single probe identified by a {@link
2N/A * ProbeDescription}. A {@code ProbeDescription} can match multiple
2N/A * probes using pattern syntax (globbing) and wildcarding (field
2N/A * omission), but it does not normally make sense to associate a {@code
2N/A * ProbeInfo} with a {@code ProbeDescription} unless that description
2N/A * matches exactly one probe on the system. A {@link Probe} pairs a
2N/A * {@code ProbeDescription} with information about the DTrace probe it
2N/A * identifies.
2N/A * <p>
2N/A * Immutable. Supports persistence using {@link java.beans.XMLEncoder}.
2N/A *
2N/A * @see Consumer#listProbeDetail(ProbeDescription filter)
2N/A * @see Consumer#listProgramProbeDetail(Program program)
2N/A *
2N/A * @author Tom Erickson
2N/A */
2N/Apublic final class ProbeInfo implements Serializable {
2N/A static final long serialVersionUID = 1057402669978245904L;
2N/A
2N/A static {
2N/A try {
2N/A BeanInfo info = Introspector.getBeanInfo(ProbeInfo.class);
2N/A PersistenceDelegate persistenceDelegate =
2N/A new DefaultPersistenceDelegate(
2N/A new String[] {"probeAttributes",
2N/A "argumentAttributes"})
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 InterfaceAttributes probeAttributes;
2N/A /** @serial */
2N/A private final InterfaceAttributes argumentAttributes;
2N/A
2N/A /**
2N/A * Creates a {@code ProbeInfo} instance from the given attributes.
2N/A * Supports XML persistence.
2N/A *
2N/A * @throws NullPointerException if any parameter is null
2N/A */
2N/A public
2N/A ProbeInfo(InterfaceAttributes singleProbeAttributes,
2N/A InterfaceAttributes argAttributes)
2N/A {
2N/A probeAttributes = singleProbeAttributes;
2N/A argumentAttributes = argAttributes;
2N/A validate();
2N/A }
2N/A
2N/A private final void
2N/A validate()
2N/A {
2N/A if (probeAttributes == null) {
2N/A throw new NullPointerException("probeAttributes is null");
2N/A }
2N/A if (argumentAttributes == null) {
2N/A throw new NullPointerException("argumentAttributes is null");
2N/A }
2N/A }
2N/A
2N/A /**
2N/A * Gets the interface attributes of a probe.
2N/A *
2N/A * @return non-null attributes including stability levels and
2N/A * dependency class
2N/A */
2N/A public InterfaceAttributes
2N/A getProbeAttributes()
2N/A {
2N/A return probeAttributes;
2N/A }
2N/A
2N/A /**
2N/A * Gets the interface attributes of the arguments to a probe.
2N/A *
2N/A * @return non-null attributes including stability levels and
2N/A * dependency class of the arguments to a probe
2N/A */
2N/A public InterfaceAttributes
2N/A getArgumentAttributes()
2N/A {
2N/A return argumentAttributes;
2N/A }
2N/A
2N/A /**
2N/A * Compares the specified object with this {@code ProbeInfo}
2N/A * instance for equality. Defines equality as having equal probe
2N/A * attributes and equal argument attributes.
2N/A *
2N/A * @return {@code true} if and only if the specified object is also
2N/A * a {@code ProbeInfo} and both instances have the same attributes
2N/A */
2N/A @Override
2N/A public boolean
2N/A equals(Object o)
2N/A {
2N/A if (o instanceof ProbeInfo) {
2N/A ProbeInfo i = (ProbeInfo)o;
2N/A return (probeAttributes.equals(i.probeAttributes) &&
2N/A argumentAttributes.equals(i.argumentAttributes));
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 int hash = 17;
2N/A hash = (37 * hash) + probeAttributes.hashCode();
2N/A hash = (37 * hash) + argumentAttributes.hashCode();
2N/A return hash;
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 // Must copy before checking 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 * Gets a string representation of this {@code ProbeInfo} 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(ProbeInfo.class.getName());
2N/A buf.append("[probeAttributes = ");
2N/A buf.append(probeAttributes);
2N/A buf.append(", argumentAttributes = ");
2N/A buf.append(argumentAttributes);
2N/A buf.append(']');
2N/A return buf.toString();
2N/A }
2N/A}