Class<? extends IPolicy> policyClass; try { policyClass = clusterViewManager.getPolicyClass(objectName); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e);
Class<? extends IPolicy> policyClass; try { policyClass = clusterViewManager.getPolicyClass(objectName); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e);
/** * Sets a property for a given object. * @param objectName a name of object * @param propertyName a name of property * @param propertyValue a value for the given name of property * @throws IllegalArgumentException if none object has the given name or if the property doesn't exist or has an invalid type * @throws UnsupportedOperationException if the used manager is at client-side */ @SuppressWarnings("unchecked") public void setPropertyForPolicy(final String objectName, final String propertyName, final String propertyValue) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } try { Class<? extends IPolicy> policyClass = clusterViewManager.getPolicyClass(objectName); ((ServerClusterViewManager) clusterViewManager).setPropertyForPolicy( objectName, propertyName, PolicyFactory.convertString(policyClass, propertyName, propertyValue)); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } catch (PropertyConfigurationException e) { throw new IllegalArgumentException("The property " + propertyName + " cannot be applied", e); } catch (ClusterViewManagerException e) { LOGGER.error("Error while finding the policy class", e); throw new RuntimeException("Error while finding the policy class", e); } }
/** * Sets a property (a list of value) for a given object. * @param objectName a name of object * @param propertyName a name of property * @param propertyValue a list of value for the given name of property * @throws IllegalArgumentException if none object has the given name, or if the property doesn't exist or has an invalid type * @throws UnsupportedOperationException if the used manager is at client-side */ @SuppressWarnings("unchecked") public void setListPropertyForPolicy(final String objectName, final String propertyName, final List<String> propertyValue) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } try { Class<? extends IPolicy> policyClass = clusterViewManager.getPolicyClass(objectName); ((ServerClusterViewManager) clusterViewManager).setPropertyForPolicy( objectName, propertyName, PolicyFactory.convertStrings(policyClass, propertyName, propertyValue)); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } catch (PropertyConfigurationException e) { throw new IllegalArgumentException("The property " + propertyName + " cannot be applied" + "\n" + e.getMessage()); } catch (ClusterViewManagerException e) { LOGGER.error("Error while finding the policy class", e); throw new RuntimeException("Error while finding the policy class", e); } }
/** * Sets a property on policy class of a given object(not object instance). * A property is either a String or a list of String. * @param objectName a name of object * @param propertyName a name of property * @param propertyValue a value for the given name of property * @throws IllegalArgumentException if none object has the given name, or if the property doesn't exist or has an invalid type * @throws UnsupportedOperationException if the used manager is at client-side */ public void setStaticPropertyForPolicy(final String objectName, final String propertyName, final String propertyValue) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } try { /** * Set property for objest that will be created further */ Class<? extends IPolicy> policyClass = clusterViewManager.getPolicyClass(objectName); ((ServerClusterViewManager)clusterViewManager).setStaticPropertyForPolicy(objectName, propertyName, PolicyFactory.convertString(policyClass, propertyName, propertyValue)); } catch (Exception e) { LOGGER.debug("Cannot set property {0} for object {1}", propertyName, objectName, e); throw new JMRuntimeException("Cannot set property " + propertyName + " for object " + objectName + "\n" + e.getMessage()); } } /**
/** * Sets the properties for a given object. A property is either a String or a list of String. * @param objectName a name of object * @param properties properties a set of properties * @throws IllegalArgumentException if none object has the given name, or if a property doesn't exist or has an invalid type * @throws UnsupportedOperationException if the used manager is at client-side */ @SuppressWarnings("unchecked") public void setPropertiesForPolicy(final String objectName, final Map<String, Object> properties) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } try { Class<? extends IPolicy> policyClass = clusterViewManager.getPolicyClass(objectName); ((ServerClusterViewManager) clusterViewManager).setPropertiesForPolicy( objectName, convertProperties(policyClass, properties)); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } catch (PropertyConfigurationException e) { throw new IllegalArgumentException( "The properties " + properties + " cannot be applied" + "\n" + e.getMessage()); } catch (ClusterViewManagerException e) { LOGGER.error("Error while finding the policy class", e); throw new RuntimeException("Error while finding the policy class", e); } }
/** * Returns a policy to access to the object with the given name. * @param objectName a name of object * @return a policy to access to the object with the given name * @throws PolicyFactoryException if the policy cannot be constructed * @throws ObjectNotFoundException if none object has the given name */ @SuppressWarnings("unchecked") public IPolicy<T> getPolicy(final String objectName) throws PolicyFactoryException, ObjectNotFoundException { Class<? extends IPolicy<T>> policyClass; try { policyClass = (Class<? extends IPolicy<T>>) clusterViewManager.getPolicyClass(objectName); } catch (ClusterViewManagerException e) { LOGGER.error("Error while finding the policy class", e); throw new PolicyFactoryException("Error while finding the policy class", e); } Map<String, Object> properties = clusterViewManager.getPropertiesForPolicy(objectName); Class<? extends IStrategy<T>> strategyClass; try { strategyClass = (Class<? extends IStrategy<T>>) clusterViewManager.getStrategyClass(objectName); } catch (ClusterViewManagerException e) { LOGGER.error("Error while finding the strategy class", e); throw new PolicyFactoryException("Error while finding the strategy class", e); } return getPolicy(policyClass, strategyClass, properties); }