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());
}
}
}
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());
}
}
}
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);
}
}
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);
}
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;
}
Aggregations