Search in sources :

Example 61 with Attribute

use of javax.management.Attribute in project JMRI by JMRI.

the class SimpleOperationsServer method sendLocationList.

/**
     * send a list of locations known by Operations to the client
     */
@Override
public void sendLocationList() {
    List<Location> locationList = lm.getLocationsByNameList();
    ArrayList<Attribute> location;
    for (Location loc : locationList) {
        location = new ArrayList<Attribute>(1);
        location.add(new Attribute(LOCATIONS, loc));
        try {
            sendMessage(location);
        } catch (IOException ioe) {
            log.debug("could not send train " + loc.getName());
        }
    }
}
Also used : Attribute(javax.management.Attribute) IOException(java.io.IOException) Location(jmri.jmrit.operations.locations.Location)

Example 62 with Attribute

use of javax.management.Attribute in project JMRI by JMRI.

the class SimpleOperationsServer method sendTrainList.

/**
     * send a list of trains known by Operations to the client
     */
@Override
public void sendTrainList() {
    List<Train> trainList = tm.getTrainsByNameList();
    ArrayList<Attribute> aTrain;
    for (Train train : trainList) {
        aTrain = new ArrayList<Attribute>(1);
        aTrain.add(new Attribute(TRAINS, train.getName()));
        try {
            sendMessage(aTrain);
        } catch (IOException ioe) {
            log.debug("could not send train " + train.getName());
        }
    }
}
Also used : Attribute(javax.management.Attribute) IOException(java.io.IOException) Train(jmri.jmrit.operations.trains.Train)

Example 63 with Attribute

use of javax.management.Attribute in project JMRI by JMRI.

the class SimpleOperationsServer method sendFullStatus.

/**
     * sends the full status for a train to a client
     *
     * @param train The desired train.
     * @throws IOException on failure to send an error message
     */
@Override
public void sendFullStatus(Train train) throws IOException {
    ArrayList<Attribute> status = new ArrayList<Attribute>();
    if (train != null) {
        status.add(new Attribute(TRAIN, train.getName()));
        status.add(new Attribute(TRAINLOCATION, train.getCurrentLocationName()));
        status.add(new Attribute(TRAINLENGTH, String.valueOf(train.getTrainLength())));
        status.add(new Attribute(TRAINWEIGHT, String.valueOf(train.getTrainWeight())));
        status.add(new Attribute(TRAINCARS, String.valueOf(train.getNumberCarsInTrain())));
        status.add(new Attribute(TRAINLEADLOCO, constructTrainLeadLoco(train.getName())));
        status.add(new Attribute(TRAINCABOOSE, constructTrainCaboose(train.getName())));
        sendMessage(status);
    }
}
Also used : Attribute(javax.management.Attribute) ArrayList(java.util.ArrayList)

Example 64 with Attribute

use of javax.management.Attribute in project jdk8u_jdk by JetBrains.

the class SnmpGenericObjectServer method set.

/**
     * Set the value of an SNMP variable.
     *
     * <p><b><i>
     * You should never need to use this method directly.
     * </i></b></p>
     *
     * @param meta  The impacted metadata object
     * @param name  The ObjectName of the impacted MBean
     * @param x     The new requested SnmpValue
     * @param id    The OID arc identifying the variable we're trying to set.
     * @param data  User contextual data allocated through the
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
     *
     * @return The new value of the variable after the operation.
     *
     * @exception SnmpStatusException whenever an SNMP exception must be
     *      raised. Raising an exception will abort the request. <br>
     *      Exceptions should never be raised directly, but only by means of
     * <code>
     * req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     **/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
    final String attname = meta.getAttributeName(id);
    final Object attvalue = meta.buildAttributeValue(id, x);
    final Attribute att = new Attribute(attname, attvalue);
    Object result = null;
    try {
        server.setAttribute(name, att);
        result = server.getAttribute(name, attname);
    } catch (InvalidAttributeValueException iv) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
    } catch (InstanceNotFoundException f) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
        throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new SnmpStatusException(SnmpStatusException.noAccess);
    }
    return meta.buildSnmpValue(id, result);
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 65 with Attribute

use of javax.management.Attribute in project jdk8u_jdk by JetBrains.

the class RelationService method initializeMissingRoles.

// Initializes roles associated to given role infos to default value (empty
// ArrayList of ObjectNames) in given relation.
// It will succeed for every role except if the role info has a minimum
// cardinality greater than 0. In that case, an InvalidRoleValueException
// will be raised.
//
// -param relationBaseFlag  flag true if the relation is a RelationSupport
//  object, false if it is an MBean
// -param relationObj  RelationSupport object (if relation is internal)
// -param relationObjName  ObjectName of the MBean to be added as a relation
//  (only for the relation MBean)
// -param relationId  relation id
// -param relationTypeName  name of the relation type (has to be created
//  in the Relation Service)
// -param roleInfoList  list of role infos for roles to be defaulted
//
// -exception IllegalArgumentException  if null paramater
// -exception RelationServiceNotRegisteredException  if the Relation
//  Service is not registered in the MBean Server
// -exception InvalidRoleValueException  if role must have a non-empty
//  value
// Revisit [cebro] Handle CIM qualifiers as REQUIRED to detect roles which
//    should have been initialized by the user
private void initializeMissingRoles(boolean relationBaseFlag, RelationSupport relationObj, ObjectName relationObjName, String relationId, String relationTypeName, List<RoleInfo> roleInfoList) throws IllegalArgumentException, RelationServiceNotRegisteredException, InvalidRoleValueException {
    if ((relationBaseFlag && (relationObj == null || relationObjName != null)) || (!relationBaseFlag && (relationObjName == null || relationObj != null)) || relationId == null || relationTypeName == null || roleInfoList == null) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }
    RELATION_LOGGER.entering(RelationService.class.getName(), "initializeMissingRoles", new Object[] { relationBaseFlag, relationObj, relationObjName, relationId, relationTypeName, roleInfoList });
    // Can throw RelationServiceNotRegisteredException
    isActive();
    // empty value, according to its minimum cardinality
    for (RoleInfo currRoleInfo : roleInfoList) {
        String roleName = currRoleInfo.getName();
        // Creates an empty value
        List<ObjectName> emptyValue = new ArrayList<ObjectName>();
        // Creates a role
        Role role = new Role(roleName, emptyValue);
        if (relationBaseFlag) {
            // RelationTypeNotFoundException
            try {
                relationObj.setRoleInt(role, true, this, false);
            } catch (RoleNotFoundException exc1) {
                throw new RuntimeException(exc1.getMessage());
            } catch (RelationNotFoundException exc2) {
                throw new RuntimeException(exc2.getMessage());
            } catch (RelationTypeNotFoundException exc3) {
                throw new RuntimeException(exc3.getMessage());
            }
        } else {
            // Relation is an MBean
            // Use standard setRole()
            Object[] params = new Object[1];
            params[0] = role;
            String[] signature = new String[1];
            signature[0] = "javax.management.relation.Role";
            // the relation MBeans are registered in the same MBean Server.
            try {
                myMBeanServer.setAttribute(relationObjName, new Attribute("Role", role));
            } catch (InstanceNotFoundException exc1) {
                throw new RuntimeException(exc1.getMessage());
            } catch (ReflectionException exc3) {
                throw new RuntimeException(exc3.getMessage());
            } catch (MBeanException exc2) {
                Exception wrappedExc = exc2.getTargetException();
                if (wrappedExc instanceof InvalidRoleValueException) {
                    throw ((InvalidRoleValueException) wrappedExc);
                } else {
                    throw new RuntimeException(wrappedExc.getMessage());
                }
            } catch (AttributeNotFoundException exc4) {
                throw new RuntimeException(exc4.getMessage());
            } catch (InvalidAttributeValueException exc5) {
                throw new RuntimeException(exc5.getMessage());
            }
        }
    }
    RELATION_LOGGER.exiting(RelationService.class.getName(), "initializeMissingRoles");
    return;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Attribute(javax.management.Attribute) InstanceNotFoundException(javax.management.InstanceNotFoundException) ArrayList(java.util.ArrayList) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) AttributeNotFoundException(javax.management.AttributeNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException)

Aggregations

Attribute (javax.management.Attribute)157 ObjectName (javax.management.ObjectName)94 MBeanServer (javax.management.MBeanServer)56 AttributeList (javax.management.AttributeList)46 Test (org.junit.Test)38 ReflectionException (javax.management.ReflectionException)29 MBeanException (javax.management.MBeanException)25 HashMap (java.util.HashMap)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)22 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)21 AttributeNotFoundException (javax.management.AttributeNotFoundException)20 MBeanServerConnection (javax.management.MBeanServerConnection)15 MBeanInfo (javax.management.MBeanInfo)14 JMXConnector (javax.management.remote.JMXConnector)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)12 List (java.util.List)10 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ArrayList (java.util.ArrayList)9