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 session. 39 */ 40 @Immutable 41 @ManagementObject( description = "A ModeShape session", componentType = @ManagementComponent( type = "ModeShape", subtype = "Session" ), properties = ManagementProperties.EXPLICIT ) 42 public final class ManagedSession implements ModeShapeManagedObject { 43 44 /** 45 * A sorter for when sessions need to be sorted by user name. 46 */ 47 public static final Comparator<ManagedSession> SORT_BY_USER = new Comparator<ManagedSession>() { 48 @Override 49 public int compare( ManagedSession thisSession, 50 ManagedSession thatSession ) { 51 return thisSession.getUserName().compareTo(thatSession.getUserName()); 52 } 53 }; 54 55 /** 56 * The JBoss managed readonly property for the session's identifier. The ID is never <code>null</code> and never empty. 57 */ 58 private final String id; 59 60 /** 61 * The JBoss managed readonly property for the session's creation time. The time is never <code>null</code>. 62 */ 63 private final DateTime timeCreated; 64 65 /** 66 * The JBoss managed readonly property for the session's user name. The user name is never <code>null</code> and never empty. 67 */ 68 private final String userName; 69 70 /** 71 * The JBoss managed readonly property for the session's workspace name. The workspace name is never <code>null</code> and 72 * never empty. 73 */ 74 private final String workspaceName; 75 76 /** 77 * Constructs a managed object for a ModeShape session. 78 * 79 * @param workspaceName the session's workspace name (never <code>null</code> and never empty) 80 * @param userName the user name of the session (never <code>null</code> and never empty) 81 * @param id the session's identifier (never <code>null</code> and never empty) 82 * @param timeCreated the session's time of creation (never <code>null</code>) 83 */ 84 public ManagedSession( String workspaceName, 85 String userName, 86 String id, 87 DateTime timeCreated ) { 88 CheckArg.isNotEmpty(workspaceName, "workspaceName"); 89 CheckArg.isNotEmpty(userName, "userName"); 90 CheckArg.isNotEmpty(id, "id"); 91 CheckArg.isNotNull(timeCreated, "timeCreated"); 92 93 this.id = id; 94 this.timeCreated = timeCreated; 95 this.userName = userName; 96 this.workspaceName = workspaceName; 97 } 98 99 /** 100 * Obtains the session's unique identifier. This is a JBoss managed readonly property. 101 * 102 * @return the identifier of this session (never <code>null</code> and never empty) 103 */ 104 @ManagementProperty( name = "Session ID", description = "The session's unique identifier", readOnly = true, use = ViewUse.RUNTIME ) 105 @ManagementObjectID( prefix = "ModeShapeSession-" ) 106 public String getId() { 107 return this.id; 108 } 109 110 /** 111 * Obtains the session's creation time. This is a JBoss managed readonly property. 112 * 113 * @return the time this session was created (never <code>null</code>) 114 */ 115 @ManagementProperty( name = "Time Created", description = "The time this session was created", readOnly = true, use = ViewUse.RUNTIME ) 116 public DateTime getTimeCreated() { 117 return this.timeCreated; 118 } 119 120 /** 121 * Obtains the session's user name. This is a JBoss managed readonly property. 122 * 123 * @return the user name of this session (never <code>null</code> and never empty) 124 */ 125 @ManagementProperty( name = "User Name", description = "The name of the session's user", readOnly = true, use = ViewUse.RUNTIME ) 126 public String getUserName() { 127 return this.userName; 128 } 129 130 /** 131 * Obtains the session's workspace name. This is a JBoss managed readonly property. 132 * 133 * @return the workspace name of this session (never <code>null</code> and never empty) 134 */ 135 @ManagementProperty( name = "Workspace Name", description = "The name of the workspace this session belongs to", readOnly = true, use = ViewUse.RUNTIME ) 136 public String getWorkspaceName() { 137 return this.workspaceName; 138 } 139 140 }