001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.management.diagnostics;
020
021import java.io.Serializable;
022import java.lang.management.LockInfo;
023
024/**
025 * Information about a lock found in a <code>ThreadInfo</code> object.
026 * @author Laurent Cohen
027 */
028public class LockInformation implements Serializable
029{
030  /**
031   * The fully qualified class name of this lock.
032   */
033  private final String className;
034  /**
035   * The identity hash code of this lock.
036   */
037  private final int identityHashcode;
038
039  /**
040   * Initialize this lock information object with the specified parameters.
041   * @param className the fully qualified class name of this lock.
042   * @param identityHashcode the identity hash code of this lock.
043   */
044  public LockInformation(final String className, final int identityHashcode)
045  {
046    this.className = className;
047    this.identityHashcode = identityHashcode;
048  }
049
050  /**
051   * Initialize this lock information from a {@link LockInfo}.
052   * @param lockInfo the fully qualified class name of this lock.
053   */
054  public LockInformation(final LockInfo lockInfo)
055  {
056    this(lockInfo.getClassName(), lockInfo.getIdentityHashCode());
057  }
058
059  /**
060   * Get the fully qualified class name of this lock.
061   * @return the class name as a string.
062   */
063  public String getClassName()
064  {
065    return className;
066  }
067
068  /**
069   * Get the identity hash code of this lock.
070   * @return the hascode as an int value.
071   */
072  public int getIdentityHashcode()
073  {
074    return identityHashcode;
075  }
076
077  @Override
078  public String toString()
079  {
080    return new StringBuilder().append(getClass().getSimpleName()).append("[className=").append(className)
081      .append(", identityHashcode=").append(identityHashcode).append(']').toString();
082  }
083}