001/* 002 * ============================================================================ 003 * Copyright © 2002-2022 by Thomas Thrien. 004 * All Rights Reserved. 005 * ============================================================================ 006 * Licensed to the public under the agreements of the GNU Lesser General Public 007 * License, version 3.0 (the "License"). You may obtain a copy of the License at 008 * 009 * http://www.gnu.org/licenses/lgpl.html 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package org.tquadrat.foundation.mgmt; 019 020import static org.apiguardian.api.API.Status.STABLE; 021 022import javax.management.DynamicMBean; 023import javax.management.InstanceAlreadyExistsException; 024import javax.management.InstanceNotFoundException; 025import javax.management.MBeanRegistrationException; 026import javax.management.NotificationEmitter; 027import javax.management.ObjectName; 028import java.util.concurrent.ThreadFactory; 029 030import org.apiguardian.api.API; 031import org.tquadrat.foundation.annotation.ClassVersion; 032import org.tquadrat.foundation.mgmt.internal.JMXSupportImpl; 033 034/** 035 * <p>{@summary The implementations of this interface will provide a dynamic 036 * MBean for the instrumentation of object annotated with 037 * {@link org.tquadrat.foundation.mgmt.ManagedObject}.}</p> 038 * 039 * @param <T> The type of the managed object. 040 * 041 * @see org.tquadrat.foundation.mgmt.ManagedObject 042 * @see org.tquadrat.foundation.mgmt.MBeanAction 043 * @see org.tquadrat.foundation.mgmt.MBeanGetter 044 * @see org.tquadrat.foundation.mgmt.MBeanNotification 045 * @see org.tquadrat.foundation.mgmt.MBeanNotifications 046 * @see org.tquadrat.foundation.mgmt.MBeanSetter 047 * 048 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 049 * @version $Id: JMXSupport.java 995 2022-01-23 01:09:35Z tquadrat $ 050 * @since 0.0.1 051 * 052 * @UMLGraph.link 053 */ 054@ClassVersion( sourceVersion = "$Id: JMXSupport.java 995 2022-01-23 01:09:35Z tquadrat $" ) 055@API( status = STABLE, since = "0.0.1" ) 056public sealed interface JMXSupport<T> extends DynamicMBean, NotificationEmitter 057 permits org.tquadrat.foundation.mgmt.internal.JMXSupportImpl 058{ 059 /*---------*\ 060 ====** Methods **========================================================== 061 \*---------*/ 062 /** 063 * Returns the sequence number that is used for the next notification. 064 * 065 * @return The next sequence number. 066 */ 067 public long getNextNotificationSequenceNumber(); 068 069 /** 070 * Returns the object that is instrumented by this MBean instance. 071 * 072 * @return The instrumented object. 073 */ 074 public T getObject(); 075 076 /** 077 * Returns the object description. 078 * 079 * @return The object description. 080 */ 081 public String getObjectDescription(); 082 083 /** 084 * Returns the object name for this MBean. This is a copy of that instance 085 * that is used during registration, not the real thing. Therefore, it 086 * should be only used for reference. 087 * 088 * @return A copy of the MBean's object name. 089 */ 090 public ObjectName getObjectName(); 091 092 /** 093 * <p>{@summary Registers the server with the JMX agent.}</p> 094 * <p>If modules are used, the registered object must be accessible for 095 * this module ({@code org.tquadrat.foundation.mgmt}). This can be 096 * achieved easiest by opening the package with the respective class to 097 * the management module.</p> 098 * 099 * @param <O> The type of the object. 100 * @param object The object to register with the JMX agent. 101 * @param objectName The object name that is used for the object to 102 * register. 103 * @param threadFactory The thread factory that is used when 104 * notifications should be sent asynchronously; can be {@code null}. 105 * @return The MBean object that was generated as the instrumentation for 106 * the object to manage. 107 * @throws IllegalArgumentException The object is not annotated with 108 * {@link org.tquadrat.foundation.mgmt.ManagedObject @ManagedObject}. 109 * @throws InstanceAlreadyExistsException There is already a MBean with 110 * the given object name registered. 111 * @throws MBeanRegistrationException Problems with the registration of 112 * the MBean. 113 */ 114 public static <O> JMXSupport<O> register( final O object, final ObjectName objectName, final ThreadFactory threadFactory ) throws IllegalArgumentException, InstanceAlreadyExistsException, MBeanRegistrationException 115 { 116 return JMXSupportImpl.register( object, objectName, threadFactory ); 117 } // register() 118 119 /** 120 * Sends an attribute change notification. The type is always 121 * {@code jmx.attribute.change}. 122 * 123 * @param <A> The type for the attribute. 124 * @param <V> The type for the values. 125 * @param message The message for this notification. 126 * @param description The description for the attribute. 127 * @param attributeType The type of the attribute. 128 * @param oldValue The old value. 129 * @param newValue The new value. 130 */ 131 public <A,V extends A> void sendAttributeChangeNotification( final String message, final String description, final Class<A> attributeType, final V oldValue, final V newValue ); 132 133 /** 134 * Sends a simple notification with a message text. 135 * 136 * @param type The type of the notification. 137 * @param message The message for this notification. 138 */ 139 public void sendNotification( final String type, final String message ); 140 141 /** 142 * Unregisters the MBean from the MBeanServer. 143 * 144 * @throws InstanceNotFoundException The MBean is not registered. 145 * @throws MBeanRegistrationException Problems with the registration of 146 * the MBean. 147 */ 148 public void unregister() throws InstanceNotFoundException, MBeanRegistrationException; 149} 150// interface JMXSupport 151 152/* 153 * End of File 154 */