Package org.jboss.mx.server

Examples of org.jboss.mx.server.MBeanInvoker


   public Object invoke(Invocation invocation) throws InvocationException
   {
      try {}
      finally
      {
         MBeanInvoker invoker = invocation.getInvoker();
         return invoker.getMetaData();
      }
   }
View Full Code Here


         Object oldValue = d.getFieldValue(VALUE);

         // check if the attribute maps to a setter
         String setMethod = (String)d.getFieldValue(SET_METHOD);

         MBeanInvoker invoker = invocation.getInvoker();              
        
         if (setMethod != null)
         { 
            // TODO: should investigate chaining invocations rather than
            //       going back to the invoker (JPL)
           
            // if setter was found, invoke the corresponding setter operation
            try
            {
               invoker.invoke(setMethod, new Object[] { value }, new String[] { invocation.getAttributeType() });
            }
            catch (Throwable t)
            {
               throw new InvocationException(t);
            }
         }

         // get the currency time limit value
         String timeLimit = (String)d.getFieldValue(CURRENCY_TIME_LIMIT);
         long limit = (timeLimit == null) ? 0 : Long.parseLong(timeLimit);
           
         // if caching is not disabled, update the descriptor fields
         if (limit != 0)
         {
            d.setField(VALUE, value);
            d.setField(LAST_UPDATED_TIME_STAMP, "" + System.currentTimeMillis() / 1000);
            invocation.setDescriptor(d);
         }
        
         // send notification
         try
         {
            ((ModelMBeanInvoker)invoker).sendAttributeChangeNotification(
               new Attribute(invocation.getName(), oldValue),
               new Attribute(invocation.getName(), value)
            );        
         }
         catch (MBeanException e)
         {
            throw new InvocationException(e, "attribute change notification error");
         }
      }
        
      else if (invocation.getType().equals(Invocation.OP_GETATTRIBUTE))
      {  
         // get the attribute's descriptor
         String getMethod = (String)d.getFieldValue(GET_METHOD);
        
         if (getMethod != null)
         {
            String timeLimit = (String)d.getFieldValue(CURRENCY_TIME_LIMIT);
            long limit = (timeLimit == null) ? 0 : Long.parseLong(timeLimit);

            if (limit == -1)
               return d.getFieldValue(VALUE);
 
            // if >0 caching is enabled
            if (limit > 0)
            {
               String timeStamp = (String)d.getFieldValue(LAST_UPDATED_TIME_STAMP);
               long lastUpdate = (timeStamp == null) ? 0 : Long.parseLong(timeStamp);
          
               // if the value hasn't gone stale, return from the descriptor
               if (System.currentTimeMillis() < lastUpdate * 1000 + limit * 1000)
                  return d.getFieldValue(VALUE);
            }

            // we got here means either stale value in descriptior, or zero time limit
            MBeanInvoker invoker = invocation.getInvoker();
            Object value = null;
           
            try
            {
               value = invoker.invoke(getMethod, new Object[0], new String[0]);
            }
            catch (Throwable t)
            {
               throw new InvocationException(t);
            }
View Full Code Here

             NotCompliantMBeanException
   {
      ObjectName regName         = name;
      boolean registrationDone   = true;
      String magicToken          = null;
      MBeanInvoker invoker       = null;
     
      if (object == null)
         throw new RuntimeOperationsException(
               new IllegalArgumentException("Attempting to register null object"));

      // FIXME: This is untidy, in the pathological case it is
      //        wrong because we modifying the entry parameter
      //        which could get reused by the caller
      // This is a fix for the SAR TCL problem in 4.0
      // Allow the classloader in the value map to be an ObjectName
      if (valueMap != null)
      {
         Object obj = valueMap.get(CLASSLOADER);
         if (obj != null && obj instanceof ObjectName)
         {
            MBeanEntry clEntry = null;
            try
            {
                clEntry = get((ObjectName) obj);
            }
            catch (InstanceNotFoundException e)
            {
               throw new RuntimeOperationsException(
                  new IllegalArgumentException(e.toString()));
            }
            valueMap.put(CLASSLOADER, clEntry.getResourceInstance());
         }
      }

      // Check the objects compliance
      MBeanCapability mbcap = MBeanCapability.of(object.getClass());

      try
      {

         if (valueMap != null)
            magicToken = (String) valueMap.get(JMI_DOMAIN);

         // TODO: allow custom factory for diff invoker types
     
         if (mbcap.getMBeanType() == MBeanCapability.STANDARD_MBEAN)
         {
            invoker = new XMBean(object, XMBeanConstants.STANDARD_MBEAN);
         }
         else if (object instanceof MBeanInvoker)
         {
            invoker = (MBeanInvoker)object;
         }
         else if (object instanceof DynamicMBean)
         {
            invoker = new RawDynamicInvoker((DynamicMBean)object);
         }


         regName = invokePreRegister(invoker, regName, magicToken);

         try
         {
            // Register the mbean

            // Test for Null MBeanInfo
            if (invoker.getMBeanInfo() == null)
               throw new NotCompliantMBeanException("Null MBeanInfo for " + name);
           
            // FIXME redundant getResource()
            MBeanEntry entry = new MBeanEntry(regName, invoker, invoker.getResource(), valueMap);

            add(entry);

            try
            {
               // Add the classloader to the repository
               if (object instanceof ClassLoader)
                  registerClassLoader((ClassLoader)object);

               try
               {
                  if (delegate != null)
                  {
                     sendRegistrationNotification (regName);
                  }
 
                  else if (name.getCanonicalName ().equals (MBEAN_SERVER_DELEGATE))
                  {
                     delegate = (MBeanServerDelegate) object;
                  }
                 
                  ServerObjectInstance serverObjInst = new ServerObjectInstance (regName,
                             entry.getResourceClassName (),
                                                   delegate.getMBeanServerId ());
                  persistIfRequired(invoker.getMBeanInfo(), regName);
                  return serverObjInst;

               }
               catch (Throwable t)
               {
                  // Problem, remove a classloader from the repository
                  if (object instanceof ClassLoader)
                     loaderRepository.removeClassLoader((ClassLoader)object);
                    
                  throw t;
               }
            }
            catch (Throwable t)
            {
               // Problem, remove the mbean from the registry
               remove(regName);
              
               throw t;
            }
         }
         // Throw for null MBeanInfo
         catch (NotCompliantMBeanException e)
         {
            throw e;
         }
         // Thrown by the registry
         catch (InstanceAlreadyExistsException e)
         {
            throw e;
         }
         catch (Throwable t)
         {
            // Something is broken
            log.error("Unexpected Exception:", t);
           
            throw t;
         }
      }
      catch (NotCompliantMBeanException e)
      {
         registrationDone = false;
         throw e;
      }
      catch (InstanceAlreadyExistsException e)
      {
         // It was already registered
         registrationDone = false;
         throw e;
      }
      catch (MBeanRegistrationException e)
      {
         // The MBean cancelled the registration
         registrationDone = false;

         log.warn(e.toString());
        
         throw e;
      }
      catch (RuntimeOperationsException e)
      {
         // There was a problem with one the arguments
         registrationDone = false;
         throw e;
      }
      catch (Throwable t)
      {
         // Some other error
         registrationDone = false;
         return null;
      }
      finally
      {
         // Tell the MBean the result of the registration
         //if (registrationInterface != null)
         //   registrationInterface.postRegister(new Boolean(registrationDone));
         if (invoker != null)
            invoker.postRegister(new Boolean(registrationDone));
      }
    }
View Full Code Here

   /**
    *
    */
   private void initMethodMap(Invocation invocation) throws Throwable
   {
      MBeanInvoker invoker = invocation.getInvoker();
      methodMap = (Map) invoker.getAttribute("MethodMap");
   }
View Full Code Here

   {
      ObjectName regName         = name;
      boolean registrationDone   = true;
      boolean invokedPreRegister = false;
      String magicToken          = null;
      MBeanInvoker invoker       = null;

      if (object == null)
         throw new RuntimeOperationsException(
               new IllegalArgumentException("Attempting to register null object"));

      // get mbean type, dynamic or standard
      MBeanCapability mbcap = MBeanCapability.of(object.getClass());

      try
      {

         if (valueMap != null)
            magicToken = (String) valueMap.get(JMI_DOMAIN);

         // TODO: allow custom factory for diff invoker types
         int mbeanType = mbcap.getMBeanType();
         if (mbeanType == MBeanCapability.STANDARD_MBEAN)
         {
            invoker = new XMBean(object, XMBeanConstants.STANDARD_MBEAN);
         }
         else if (object instanceof MBeanInvoker)
         {
            invoker = (MBeanInvoker)object;
         }
         else if (mbeanType == MBeanCapability.DYNAMIC_MBEAN)
         {
            if( object instanceof RequiredModelMBean )
               invoker = new RequiredModelMBeanInvoker((DynamicMBean)object);
            else
               invoker = new RawDynamicInvoker((DynamicMBean)object);
         }

         // Perform the pregistration
         MBeanEntry entry = new MBeanEntry(regName, invoker, object, valueMap);
         AbstractMBeanInvoker.setMBeanEntry(entry);
         regName = invokePreRegister(invoker, regName, magicToken);
         invokedPreRegister = true;

         try
         {
            MBeanInfo info = invoker.getMBeanInfo();
            verifyMBeanInfo(info, name);
            entry.setResourceClassName(info.getClassName());

            // Register the mbean

            // Update the registered name to the final value
            entry.setObjectName(regName);

            add(entry);

            try
            {
               // Add the classloader to the repository
               if (object instanceof ClassLoader)
                  registerClassLoader((ClassLoader)object);

               try
               {
                  if (delegate != null)
                     sendRegistrationNotification (regName);
                  else if (serverConfig.getMBeanServerDelegateName().equals(name))
                     delegate = (MBeanServerDelegate) object;

                  ServerObjectInstance serverObjInst = new ServerObjectInstance
                        (regName, entry.getResourceClassName(), delegate.getMBeanServerId());

                  persistIfRequired(invoker.getMBeanInfo(), regName);

                  return serverObjInst;

               }
               catch (Throwable t)
               {
                  // Problem, remove a classloader from the repository
                  if (object instanceof ClassLoader)
                     loaderRepository.removeClassLoader((ClassLoader)object);

                  throw t;
               }
            }
            catch (Throwable t)
            {
               // Problem, remove the mbean from the registry
               remove(regName);
               throw t;
            }
         }
         // Throw for null MBeanInfo
         catch (NotCompliantMBeanException e)
         {
            throw e;
         }
         // Thrown by the registry
         catch (InstanceAlreadyExistsException e)
         {
            throw e;
         }
         catch (Throwable t)
         {
            // Something is broken
            log.error("Unexpected Exception:", t);
            throw t;
         }
      }
      catch (NotCompliantMBeanException e)
      {
         registrationDone = false;
         throw e;
      }
      catch (InstanceAlreadyExistsException e)
      {
         // It was already registered
         registrationDone = false;
         throw e;
      }
      catch (MBeanRegistrationException e)
      {
         // The MBean cancelled the registration
         registrationDone = false;
         log.warn(e.toString());
         throw e;
      }
      catch (RuntimeOperationsException e)
      {
         // There was a problem with one the arguments
         registrationDone = false;
         throw e;
      }
      catch (Exception ex)
      {
         // any other exception is mapped to NotCompliantMBeanException
         registrationDone = false;
         NotCompliantMBeanException ncex = new NotCompliantMBeanException("Cannot register MBean: " + name);
         ncex.initCause(ex);
         throw ncex;
      }
      catch (Throwable t)
      {
         // Some other error
         log.error("Cannot register MBean", t);
         registrationDone = false;
         return null;
      }
      finally
      {
         // Tell the MBean the result of the registration
         if (invoker != null)
         {
            try
            {
               invoker.postRegister(new Boolean(registrationDone));
            }
            catch(Exception e)
            {
               // Only throw this if preRegister succeeded
               if( invokedPreRegister == true )
View Full Code Here

                  target = descriptorTarget;
               }
               String getMethodString = (String) d.getFieldValue(ModelMBeanConstants.GET_METHOD);
               if (getMethodString != null && (getMethod == null || getMethodString.equals(getMethod.getName()) == false))
               {
                  MBeanInvoker invoker = invocation.getInvoker();
                  Object object = invoker.invoke(getMethodString, new Object[0], new String[0]);
                  checkAssignable(getMethodString, invocation.getAttributeTypeClass(), object);
                  return object;
               }
            }
         }
         if (target == null)
            throw new MBeanException(new ServiceNotFoundException("No Target"));
         try
         {
            value = getMethod.invoke(target, args);
         }
         catch (Throwable t)
         {
            handleInvocationExceptions(t);
            return null;
         }
      }
      // Setter
      else
      {
         Method setMethod = setter;
         if (dynamic)
         {
            Descriptor d = invocation.getDescriptor();
            if (d != null)
            {
               Object descriptorTarget = d.getFieldValue(ModelMBeanConstants.TARGET_OBJECT);
               if (descriptorTarget != null)
               {
                  String targetType = (String) d.getFieldValue(ModelMBeanConstants.TARGET_TYPE);
                  if (ModelMBeanConstants.OBJECT_REF.equalsIgnoreCase(targetType) == false)
                     throw new InvalidTargetObjectTypeException("Target type is " + targetType);
                  target = descriptorTarget;
               }
               String setMethodString = (String) d.getFieldValue(ModelMBeanConstants.SET_METHOD);
               if (setMethodString != null && (setMethod == null || setMethodString.equals(setMethod.getName()) == false))
               {
                  MBeanInvoker invoker = invocation.getInvoker();
                  return invoker.invoke(setMethodString, new Object[] { args[0] }, new String[] { invocation.getAttributeType() });
               }
            }
         }
         if (target == null)
            throw new MBeanException(new ServiceNotFoundException("No Target"));
View Full Code Here

    * @return
    * @throws InvocationException
    */
   public Object invoke(Invocation invocation) throws Throwable
   {
      MBeanInvoker invoker = invocation.getInvoker();
      return invoker.getMetaData();
   }
View Full Code Here

      if (policy == null)
         policy = mbeanPersistencePolicy;

      if (policy.equalsIgnoreCase(PP_ON_UPDATE) == true)
      {
         MBeanInvoker invoker = invocation.getInvoker();
         Descriptor attrDesc = invocation.getDescriptor();
         invoker.updateAttributeInfo(attrDesc);
         callback.store();
      }
      else if(policy.equalsIgnoreCase(PP_NO_MORE_OFTEN_THAN) == true)
      {
         PersistenceTimerTask task = (PersistenceTimerTask) timerTaskMap.get(attrName);
View Full Code Here

    * @param invocation
    */
   private synchronized void lazyInit(Invocation invocation) throws MBeanException
   {
      // This requires the invoker to implement PersistentMBean
      MBeanInvoker invoker = invocation.getInvoker();
      callback = (PersistentMBean) invocation.getInvoker();
      ModelMBeanInfo info = (ModelMBeanInfo) invoker.getMetaData();
      Descriptor mbeanDesc = info.getMBeanDescriptor();

      String policy = (String) mbeanDesc.getFieldValue(PERSIST_POLICY);
      String persistPeriod = (String)mbeanDesc.getFieldValue(PERSIST_PERIOD);

View Full Code Here

/*     */   {
/* 182 */     ObjectName regName = name;
/* 183 */     boolean registrationDone = true;
/* 184 */     boolean invokedPreRegister = false;
/* 185 */     String magicToken = null;
/* 186 */     MBeanInvoker invoker = null;
/*     */
/* 188 */     if (object == null) {
/* 189 */       throw new RuntimeOperationsException(new IllegalArgumentException("Attempting to register null object"));
/*     */     }
/*     */
/* 193 */     MBeanCapability mbcap = MBeanCapability.of(object.getClass());
/*     */     try
/*     */     {
/* 198 */       if (valueMap != null) {
/* 199 */         magicToken = (String)valueMap.get(JMI_DOMAIN);
/*     */       }
/*     */
/* 202 */       int mbeanType = mbcap.getMBeanType();
/* 203 */       if (mbeanType == 291)
/*     */       {
/* 205 */         invoker = new XMBean(object, "StandardMBean");
/*     */       }
/* 207 */       else if ((object instanceof MBeanInvoker))
/*     */       {
/* 209 */         invoker = (MBeanInvoker)object;
/*     */       }
/* 211 */       else if (mbeanType == 801)
/*     */       {
/* 213 */         if ((object instanceof RequiredModelMBean))
/* 214 */           invoker = new RequiredModelMBeanInvoker((DynamicMBean)object);
/*     */         else {
/* 216 */           invoker = new RawDynamicInvoker((DynamicMBean)object);
/*     */         }
/*     */       }
/*     */
/* 220 */       MBeanEntry entry = new MBeanEntry(regName, invoker, object, valueMap);
/* 221 */       AbstractMBeanInvoker.setMBeanEntry(entry);
/* 222 */       regName = invokePreRegister(invoker, regName, magicToken);
/* 223 */       invokedPreRegister = true;
/*     */       try
/*     */       {
/* 227 */         MBeanInfo info = invoker.getMBeanInfo();
/* 228 */         verifyMBeanInfo(info, name);
/* 229 */         entry.setResourceClassName(info.getClassName());
/*     */
/* 234 */         entry.setObjectName(regName);
/*     */
/* 236 */         add(entry);
/*     */         try
/*     */         {
/* 241 */           if ((object instanceof ClassLoader)) {
/* 242 */             registerClassLoader((ClassLoader)object);
/*     */           }
/*     */           try
/*     */           {
/* 246 */             if (this.delegate != null)
/* 247 */               sendRegistrationNotification(regName);
/* 248 */             else if (serverConfig.getMBeanServerDelegateName().equals(name)) {
/* 249 */               this.delegate = ((MBeanServerDelegate)object);
/*     */             }
/* 251 */             ServerObjectInstance serverObjInst = new ServerObjectInstance(regName, entry.getResourceClassName(), this.delegate.getMBeanServerId());
/*     */
/* 254 */             persistIfRequired(invoker.getMBeanInfo(), regName);
/*     */
/* 256 */             ServerObjectInstance localServerObjectInstance1 = serverObjInst;
/*     */
/* 334 */             if (invoker != null)
/*     */             {
/*     */               try
/*     */               {
/* 338 */                 invoker.postRegister(new Boolean(registrationDone));
/*     */               }
/*     */               catch (Exception e)
/*     */               {
/* 343 */                 if (invokedPreRegister == true)
/*     */                 {
/* 345 */                   if ((e instanceof RuntimeException)) {
/* 346 */                     throw new RuntimeMBeanException((RuntimeException)e);
/*     */                   }
/* 348 */                   throw new MBeanRegistrationException(e);
/*     */                 }
/*     */               }
/*     */             }
/* 352 */             AbstractMBeanInvoker.setMBeanEntry(null); return localServerObjectInstance1;
/*     */           }
/*     */           catch (Throwable t)
/*     */           {
/* 262 */             if ((object instanceof ClassLoader)) {
/* 263 */               this.loaderRepository.removeClassLoader((ClassLoader)object);
/*     */             }
/* 265 */             throw t;
/*     */           }
/*     */
/*     */         }
/*     */         catch (Throwable t)
/*     */         {
/* 271 */           remove(regName);
/* 272 */           throw t;
/*     */         }
/*     */
/*     */       }
/*     */       catch (NotCompliantMBeanException e)
/*     */       {
/* 278 */         throw e;
/*     */       }
/*     */       catch (InstanceAlreadyExistsException e)
/*     */       {
/* 283 */         throw e;
/*     */       }
/*     */       catch (Throwable t)
/*     */       {
/* 288 */         log.error("Unexpected Exception:", t);
/* 289 */         throw t;
/*     */       }
/*     */     }
/*     */     catch (NotCompliantMBeanException e)
/*     */     {
/* 294 */       registrationDone = false;
/* 295 */       throw e;
/*     */     }
/*     */     catch (InstanceAlreadyExistsException e)
/*     */     {
/* 300 */       registrationDone = false;
/* 301 */       throw e;
/*     */     }
/*     */     catch (MBeanRegistrationException e)
/*     */     {
/* 306 */       registrationDone = false;
/* 307 */       log.warn(e.toString());
/* 308 */       throw e;
/*     */     }
/*     */     catch (RuntimeOperationsException e)
/*     */     {
/* 313 */       registrationDone = false;
/* 314 */       throw e;
/*     */     }
/*     */     catch (Exception ex)
/*     */     {
/* 319 */       registrationDone = false;
/* 320 */       ncex = new NotCompliantMBeanException("Cannot register MBean: " + name);
/* 321 */       ncex.initCause(ex);
/* 322 */       throw ncex;
/*     */     }
/*     */     catch (Throwable t)
/*     */     {
/* 327 */       log.error("Cannot register MBean", t);
/* 328 */       registrationDone = false;
/* 329 */       NotCompliantMBeanException ncex = null;
/*     */       return ncex;
/*     */     }
/*     */     finally
/*     */     {
/* 334 */       if (invoker != null)
/*     */       {
/*     */         try
/*     */         {
/* 338 */           invoker.postRegister(new Boolean(registrationDone));
/*     */         }
/*     */         catch (Exception e)
/*     */         {
/* 343 */           if (invokedPreRegister == true)
/*     */           {
View Full Code Here

TOP

Related Classes of org.jboss.mx.server.MBeanInvoker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.