View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors. 
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   *
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.jboss.managed;
25  
26  import java.util.Comparator;
27  import net.jcip.annotations.Immutable;
28  import org.jboss.managed.api.annotation.ManagementComponent;
29  import org.jboss.managed.api.annotation.ManagementObject;
30  import org.jboss.managed.api.annotation.ManagementObjectID;
31  import org.jboss.managed.api.annotation.ManagementProperties;
32  import org.jboss.managed.api.annotation.ManagementProperty;
33  import org.jboss.managed.api.annotation.ViewUse;
34  import org.joda.time.DateTime;
35  import org.modeshape.common.util.CheckArg;
36  
37  /**
38   * The <code>ManagedSession</code> class is a JBoss managed object of a ModeShape lock.
39   */
40  @Immutable
41  @ManagementObject( description = "A ModeShape node lock", componentType = @ManagementComponent( type = "ModeShape", subtype = "Lock" ), properties = ManagementProperties.EXPLICIT )
42  public final class ManagedLock implements ModeShapeManagedObject {
43  
44      /**
45       * A sorter for when locks need to be sorted by owner.
46       */
47      public static final Comparator<ManagedLock> SORT_BY_OWNER = new Comparator<ManagedLock>() {
48          @Override
49          public int compare( ManagedLock thisLock,
50                              ManagedLock thatLock ) {
51              return thisLock.getOwner().compareTo(thatLock.getOwner());
52          }
53      };
54  
55      /**
56       * The JBoss managed readonly property indicating if this lock is a deep lock.
57       */
58      private final boolean deep;
59  
60      /**
61       * The JBoss managed readonly property for the lock's expiration time. The expiration time is never <code>null</code>.
62       */
63      private final DateTime expiration;
64  
65      /**
66       * The JBoss managed readonly property for the lock's identifier. The ID is never <code>null</code> and never empty.
67       */
68      private final String id;
69  
70      /**
71       * The JBoss managed readonly property for the lock's session identifier. The session ID is never <code>null</code> and never
72       * empty.
73       */
74      private final String sessionId;
75  
76      /**
77       * The JBoss managed readonly property for the lock's owner. The owner is never <code>null</code> and never empty.
78       */
79      private final String owner;
80  
81      /**
82       * The JBoss managed readonly property indicating if this lock is a session-based lock.
83       */
84      private final boolean sessionBased;
85  
86      /**
87       * The JBoss managed readonly property for the lock's workspace name. The workspace name is never <code>null</code> and never
88       * empty.
89       */
90      private final String workspaceName;
91  
92      /**
93       * Constructs a managed object for a ModeShape lock.
94       * 
95       * @param workspaceName the name of the lock's workspace (never <code>null</code> and never empty)
96       * @param sessionBased the flag indicating if this lock is session-based
97       * @param sessionId the session ID of this lock (never <code>null</code> and never empty)
98       * @param expiration the lock expiration time (never <code>null</code>)
99       * @param id the lock ID (never <code>null</code> and never empty)
100      * @param owner the owner of the lock (never <code>null</code> or empty)
101      * @param deep the flag indicating if this is a deep lock
102      */
103     public ManagedLock( String workspaceName,
104                         boolean sessionBased,
105                         String sessionId,
106                         DateTime expiration,
107                         String id,
108                         String owner,
109                         boolean deep ) {
110         CheckArg.isNotEmpty(workspaceName, "workspaceName");
111         CheckArg.isNotEmpty(sessionId, "sessionId");
112         CheckArg.isNotNull(expiration, "expiration");
113         CheckArg.isNotEmpty(id, "id");
114         CheckArg.isNotEmpty(owner, "owner");
115 
116         this.deep = deep;
117         this.expiration = expiration;
118         this.id = id;
119         this.sessionId = sessionId;
120         this.owner = owner;
121         this.sessionBased = sessionBased;
122         this.workspaceName = workspaceName;
123     }
124 
125     /**
126      * Obtains the lock's expiration time. This is a JBoss managed readonly property.
127      * 
128      * @return the time this lock will expire (never <code>null</code>)
129      */
130     @ManagementProperty( name = "Expiration Time", description = "The time this lock will expire", readOnly = true, use = ViewUse.RUNTIME )
131     public DateTime getExpiration() {
132         return this.expiration;
133     }
134 
135     /**
136      * Obtains the lock's identifier. This is a JBoss managed readonly property.
137      * 
138      * @return the identifier of this lock (never <code>null</code> and never empty)
139      */
140     @ManagementProperty( name = "Lock ID", description = "The lock's unique identifier", readOnly = true, use = ViewUse.RUNTIME )
141     @ManagementObjectID( prefix = "ModeShapeLock-" )
142     public String getId() {
143         return this.id;
144     }
145 
146     /**
147      * Obtains the lock's owner. This is a JBoss managed readonly property.
148      * 
149      * @return the owner of this lock (never <code>null</code> and never empty)
150      */
151     @ManagementProperty( name = "Owner", description = "The owner of the lock", readOnly = true, use = ViewUse.RUNTIME )
152     public String getOwner() {
153         return this.owner;
154     }
155 
156     /**
157      * Obtains the session's unique identifier. This is a JBoss managed readonly property.
158      * 
159      * @return the session identifier of this lock (never <code>null</code> and never empty)
160      */
161     @ManagementProperty( name = "Session ID", description = "The identifier of the session this lock belongs to", readOnly = true, use = ViewUse.RUNTIME )
162     public String getSessionId() {
163         return this.sessionId;
164     }
165 
166     /**
167      * Obtains the lock's workspace name. This is a JBoss managed readonly property.
168      * 
169      * @return the workspace name of this lock (never <code>null</code> and never empty)
170      */
171     @ManagementProperty( name = "Workspace", description = "The name of the workspace lock belongs to", readOnly = true, use = ViewUse.RUNTIME )
172     public String getWorkspaceName() {
173         return this.workspaceName;
174     }
175 
176     /**
177      * Indicates if this lock is a deep lock. This is a JBoss managed readonly property.
178      * 
179      * @return <code>true</code> if a deep lock
180      */
181     @ManagementProperty( name = "Deep", description = "Indicates if this lock is a deep lock", readOnly = true, use = ViewUse.RUNTIME )
182     public boolean isDeep() {
183         return this.deep;
184     }
185 
186     /**
187      * Indicates if this lock is a session-based lock. This is a JBoss managed readonly property.
188      * 
189      * @return <code>true</code> if a session-based lock
190      */
191     @ManagementProperty( name = "Session-Based", description = "Indicates if this lock is a session-based lock", readOnly = true, use = ViewUse.RUNTIME )
192     public boolean isSessionBased() {
193         return this.sessionBased;
194     }
195 
196 }