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.concurrent.TimeUnit;
27  import org.jboss.managed.api.ManagedOperation.Impact;
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.ManagementOperation;
32  import org.jboss.managed.api.annotation.ManagementProperties;
33  import org.jboss.managed.api.annotation.ManagementProperty;
34  import org.jboss.managed.api.annotation.ViewUse;
35  import org.modeshape.common.util.CheckArg;
36  import org.modeshape.common.util.Logger;
37  import org.modeshape.common.util.Logger.Level;
38  import org.modeshape.graph.connector.RepositorySource;
39  
40  /**
41   * A <code>ManagedConnector</code> instance is a JBoss managed object for a {@link RepositorySource repository source}.
42   */
43  @ManagementObject( description = "A ModeShape connector (repository source)", componentType = @ManagementComponent( type = "ModeShape", subtype = "Connector" ), properties = ManagementProperties.EXPLICIT )
44  public class ManagedConnector implements ModeShapeManagedObject {
45  
46      // TODO get rid of this constructor
47      protected ManagedConnector() {
48          this.connector = null;
49      }
50  
51      /****************************** above for temporary testing only ***********************************************************/
52  
53      // TODO find other properties using reflection and make them readonly properties
54  
55      /**
56       * The ModeShape object being managed and delegated to (never <code>null</code>).
57       */
58      private final RepositorySource connector;
59  
60      /**
61       * Creates a JBoss managed object for the specified repository source.
62       * 
63       * @param connector the repository source being managed (never <code>null</code>)
64       */
65      public ManagedConnector( RepositorySource connector ) {
66          CheckArg.isNotNull(connector, "connector");
67          this.connector = connector;
68      }
69  
70      /**
71       * Obtains the maximum number of retries to perform on an operation. This is a JBoss managed writable property.
72       * 
73       * @return the number of retries
74       */
75      @ManagementProperty( name = "Retry Limit", description = "The maximum number of retries to perform on an operation", readOnly = false, use = ViewUse.RUNTIME )
76      public int getRetryLimit() {
77          return this.connector.getRetryLimit();
78      }
79  
80      /**
81       * Obtains the name of the repository source. This is a JBoss managed readonly property.
82       * 
83       * @return the name of the connector
84       */
85      @ManagementProperty( name = "Connector Name", description = "The name of the repository source", readOnly = true, use = ViewUse.CONFIGURATION )
86      @ManagementObjectID(prefix="ModeShape-")
87      public String getName() {
88          return this.connector.getName();
89      }
90  
91      /**
92       * Indicates if the repository source supports creating workspaces. This is a JBoss managed readonly property.
93       * 
94       * @return <code>true</code> if created workspaces is supported
95       */
96      @ManagementProperty( name = "Supports Creating Workspaces", description = "Indicates if creating workspaces is allowed", readOnly = true, use = ViewUse.CONFIGURATION )
97      public boolean isSupportingCreatingWorkspaces() {
98          return this.connector.getCapabilities().supportsCreatingWorkspaces();
99      }
100 
101     /**
102      * Indicates if the repository source supports publishing change events. This is a JBoss managed readonly property.
103      * 
104      * @return <code>true</code> if events are supported
105      */
106     @ManagementProperty( name = "Supports Events", description = "Indicates if the publishing of changes events is supported", readOnly = true, use = ViewUse.CONFIGURATION )
107     public boolean isSupportingEvents() {
108         return this.connector.getCapabilities().supportsEvents();
109     }
110 
111     /**
112      * Indicates if the repository source supports creating locks. This is a JBoss managed readonly property.
113      * 
114      * @return <code>true</code> if locking is supported
115      */
116     @ManagementProperty( name = "Supports Locks", description = "Indicates if locks can be created", readOnly = true, use = ViewUse.CONFIGURATION )
117     public boolean isSupportingLocks() {
118         return this.connector.getCapabilities().supportsLocks();
119     }
120 
121     /**
122      * Indicates if the repository source supports queries. This is a JBoss managed readonly property.
123      * 
124      * @return <code>true</code> if queries are supported
125      */
126     @ManagementProperty( name = "Supports Queries", description = "Indicates if queries are supported", readOnly = true, use = ViewUse.CONFIGURATION )
127     public boolean isSupportingQueries() {
128         return this.connector.getCapabilities().supportsQueries();
129     }
130 
131     /**
132      * Indicates if the repository source supports references by identifiers. This is a JBoss managed readonly property.
133      * 
134      * @return <code>true</code> if references are supported
135      */
136     @ManagementProperty( name = "Supports References", description = "Indicates if references by identifiers are supported", readOnly = true, use = ViewUse.CONFIGURATION )
137     public boolean isSupportingReferences() {
138         return this.connector.getCapabilities().supportsReferences();
139     }
140 
141     /**
142      * Indicates if the repository source supports siblings being able to have the same name. This is a JBoss managed readonly
143      * property.
144      * 
145      * @return <code>true</code> if same name siblings are supported
146      */
147     @ManagementProperty( name = "Supports Same Name Siblings", description = "Indicates if siblings can have the same name", readOnly = true, use = ViewUse.CONFIGURATION )
148     public boolean isSupportingSameNameSiblings() {
149         return this.connector.getCapabilities().supportsSameNameSiblings();
150     }
151 
152     /**
153      * Indicates if the repository source supports full-text searches. This is a JBoss managed readonly property.
154      * 
155      * @return <code>true</code> if searches are supported
156      */
157     @ManagementProperty( name = "Supports Searches", description = "Indicates if full-text searches are supported", readOnly = true, use = ViewUse.CONFIGURATION )
158     public boolean isSupportingSearches() {
159         return this.connector.getCapabilities().supportsSearches();
160     }
161 
162     /**
163      * Indicates if the repository source supports updates. This is a JBoss managed readonly property.
164      * 
165      * @return <code>true</code> if updates are supported
166      */
167     @ManagementProperty( name = "Supports Updates", description = "Indicates if updates can be made to the repository source", readOnly = true, use = ViewUse.CONFIGURATION )
168     public boolean isSupportingUpdates() {
169         return this.connector.getCapabilities().supportsUpdates();
170     }
171 
172     /**
173      * Indicates if the connection is valid and alive. This is a JBoss managed operation.
174      * 
175      * @return true if connection can still be used
176      */
177     @ManagementOperation( description = "Indicates if the connection is valid and alive", impact = Impact.ReadOnly )
178     public boolean ping() {
179         try {
180             return this.connector.getConnection().ping(2, TimeUnit.SECONDS);
181         } catch (Exception e) {
182             Logger.getLogger(getClass()).log(Level.ERROR,
183                                              e,
184                                              JBossManagedI18n.errorDeterminingIfConnectionIsAlive,
185                                              this.connector.getName());
186             return false;
187         }
188     }
189 
190     /**
191      * Sets the maximum number of retries to perform on an operation. This is a JBoss managed property.
192      * 
193      * @param limit the new retry limit (must be non-negative)
194      */
195     public void setRetryLimit( int limit ) {
196         CheckArg.isNonNegative(limit, "limit");
197         this.connector.setRetryLimit(limit);
198     }
199 
200 }