public static <T extends ConfigBeanProxy> T createChild(ConfigBeanProxy self, Class<T> c) throws TransactionFailure { try { WriteableView bean = WriteableView.class.cast(Proxy.getInvocationHandler(Proxy.class.cast(self))); return bean.allocateProxy(c); } catch (ClassCastException e) { throw new TransactionFailure("Must use a locked parent config object for instantiating new config object", e); } }
static <T extends ConfigBeanProxy> WriteableView getWriteableView(T s, ConfigBean sourceBean) throws TransactionFailure { WriteableView f = new WriteableView(s); try { if (sourceBean.getLock().tryLock(lockTimeOutInSeconds, TimeUnit.SECONDS)) { sourceBean.setWriteableView(f); return f; } } catch(InterruptedException e) { // ignore, will throw a TransactionFailure exception } throw new TransactionFailure("Config bean already locked " + sourceBean, null); }
final String value = getPropertyValue(key); if ( value == null ) { throw new TransactionFailure( "Key value cannot be null: " + key ); throw new TransactionFailure( "Key value cannot be empty string: " + key ); throw new TransactionFailure(e.getMessage(), e); throw e; } catch(Exception e) { throw new TransactionFailure(e.getMessage(), e); } finally { bean.getLock().unlock();
/** * Returns true of this Transaction can be committed on this object * * @param t is the transaction to commit, should be the same as the * one passed during the join(Transaction t) call. * @return true if the trsaction commiting would be successful */ public synchronized boolean canCommit(Transaction t) throws TransactionFailure { if (!isDeleted) { // HK2-127: validate only if not marked for deletion Set constraintViolations = beanValidator.validate(this.getProxy(this.getProxyType())); try { handleValidationException(constraintViolations); } catch (ConstraintViolationException constraintViolationException) { throw new TransactionFailure(constraintViolationException.getMessage(), constraintViolationException); } } return currentTx==t; }
private static void applyProperties(WriteableView target, List<? extends AttributeChanges> changes) throws TransactionFailure { if (changes != null) { for (AttributeChanges change : changes) { ConfigModel.Property prop = target.getProperty(change.getName()); if (prop == null) { throw new TransactionFailure("Unknown property name " + change.getName() + " on " + target.getProxyType()); } if (prop.isCollection()) { // we need access to the List try { List list = (List) target.getter(prop, ConfigSupport.class.getDeclaredMethod("defaultPropertyValue", null).getGenericReturnType()); for (String value : change.values()) { list.add(value); } } catch (NoSuchMethodException e) { throw new TransactionFailure(e.getMessage(), e); } } else { target.setter(prop, change.values()[0], String.class); } } } } }
if (!writeable.join(t)) { t.rollback(); throw new TransactionFailure("Cannot enlist " + source.getProxyType() + " in transaction", null); ConfigModel.Property prop = writeable.getProperty(xmlName); if (prop == null) { throw new TransactionFailure("Unknown property name " + xmlName + " on " + source.getProxyType(), null); values.add(change.getValue()); } catch (NoSuchMethodException e) { throw new TransactionFailure("Unknown property name " + xmlName + " on " + source.getProxyType(), null); } catch (Exception e) { t.rollback(); throw new TransactionFailure(e.getMessage(), e); throw new TransactionFailure(e.getMessage(), e); } catch (TransactionFailure e) { System.out.println("failure, not retryable...");
list = (List) m.invoke(writeableParent.getProxy(writeableParent.<ConfigBeanProxy>getProxyType()), null); } catch (IllegalAccessException e) { throw new TransactionFailure("Exception while adding to the parent", e); } catch (InvocationTargetException e) { throw new TransactionFailure("Exception while adding to the parent", e); throw new TransactionFailure("Parent " + parent.getProxyType() + " does not have a child of type " + childType);
throw new TransactionFailure("EXCEPTION getting class for " + elementModel.targetTypeName, ex); list = (List) m.invoke(param, null); } catch (IllegalAccessException e) { throw new TransactionFailure("Exception while adding to the parent", e); } catch (InvocationTargetException e) { throw new TransactionFailure("Exception while adding to the parent", e); throw new TransactionFailure("Parent " + parent.getProxyType() + " does not have a child of type " + childType);
public static ConfigBeanProxy deepCopy(ConfigBeanProxy self, ConfigBeanProxy parent) throws TransactionFailure { ConfigBean configBean = (ConfigBean) Dom.unwrap(self); // ensure the parent is locked Transaction t = Transaction.getTransaction(parent); if (t==null) { throw new TransactionFailure("Must use a locked parent config object for copying new config object"); } ConfigBean copy = configBean.copy(configBean.parent()); return t.enroll(copy.createProxy()); }
if (!view.join(t)) { t.rollback(); throw new TransactionFailure("Cannot enlist " + view.getMasterView().getProxyType() + " in transaction", null); t.rollback(); Throwable throwable = e.getCause(); if (throwable instanceof PropertyVetoException) throw new TransactionFailure(throwable.toString(), throwable); throw new TransactionFailure(e.toString(), e); } catch (Exception e) { t.rollback(); throw new TransactionFailure(e.getMessage(), e);
/** * Enroll a configuration object in a transaction and returns a writeable view of it * * @param source the configured interface implementation * @return the new interface implementation providing write access * @throws TransactionFailure if the object cannot be enrolled (probably already enrolled in * another transaction). */ public <T extends ConfigBeanProxy> T enroll(final T source) throws TransactionFailure { T configBeanProxy = ConfigSupport.revealProxy(source); ConfigView sourceBean = (ConfigView) Proxy.getInvocationHandler(configBeanProxy); WriteableView writeableView = ConfigSupport.getWriteableView(configBeanProxy, (ConfigBean) sourceBean.getMasterView()); if (!writeableView.join(this)) { throw new TransactionFailure("Cannot join transaction : " + sourceBean.getProxyType()); } return (T) writeableView.getProxy(sourceBean.getProxyType()); }
/** * Allocate a new ConfigBean object as part of the Transaction * associated with this configuration object. This will eventually * be moved to a factory. * * @param type the request configuration object type * @return the propertly constructed configuration object * @throws TransactionFailure if the allocation failed */ public <T extends ConfigBeanProxy> T allocateProxy(Class<T> type) throws TransactionFailure { if (currentTx==null) { throw new TransactionFailure("Not part of a transaction", null); } ConfigBean newBean = bean.allocate(type); WriteableView writeableView = bean.getHabitat().<ConfigSupport>getService(ConfigSupport.class).getWriteableView(newBean.getProxy(type), newBean); writeableView.join(currentTx); return writeableView.getProxy(type); }
public static <T extends ConfigBeanProxy> T createChild(ConfigBeanProxy self, Class<T> c) throws TransactionFailure { try { WriteableView bean = WriteableView.class.cast(Proxy.getInvocationHandler(Proxy.class.cast(self))); return bean.allocateProxy(c); } catch (ClassCastException e) { throw new TransactionFailure("Must use a locked parent config object for instantiating new config object", e); } }
public static <T extends ConfigBeanProxy> T createChild(ConfigBeanProxy self, Class<T> c) throws TransactionFailure { try { WriteableView bean = WriteableView.class.cast(Proxy.getInvocationHandler(Proxy.class.cast(self))); return bean.allocateProxy(c); } catch (ClassCastException e) { throw new TransactionFailure("Must use a locked parent config object for instantiating new config object", e); } }
static <T extends ConfigBeanProxy> WriteableView getWriteableView(final T s, final ConfigBean sourceBean) throws TransactionFailure { final WriteableView f = new WriteableView(s); if (sourceBean.getLock().tryLock()) { return f; } throw new TransactionFailure("Config bean already locked " + sourceBean, null); }
/** * * @param ports * @param serverName * @return a message if error, nu8ll means A-OK */ private static void checkForLegalPorts(Set<Integer> ports, String serverName) throws TransactionFailure { for (int port : ports) if (!NetUtils.isPortValid(port)) throw new TransactionFailure(Strings.get("PortUtils.illegal_port_number", port, serverName, MAX_PORT)); } }
@Override public Object run(ConfigBeanProxy... params) throws PropertyVetoException, TransactionFailure { Cluster wCluster = (Cluster) params[0]; VirtualMachineConfig vmConfig = config.getExtensionsByTypeAndName(VirtualMachineConfig.class, vm.getName()); if (vmConfig!=null) { wCluster.getExtensions().remove(vmConfig); } else { throw new TransactionFailure("Cannot find virtual machine configuration under cluster"); } return null; } }, config, vm.getServerPool().getConfig());
@Override public void decorate(AdminCommandContext context, SecureAdminInternalUser instance) throws TransactionFailure, PropertyVetoException { try { helper.validateInternalUsernameAndPasswordAlias( username, passwordAlias); } catch (Exception ex) { throw new TransactionFailure("create", ex); } instance.setUsername(username); instance.setPasswordAlias(passwordAlias); }
public static ConfigBeanProxy deepCopy(ConfigBeanProxy self, ConfigBeanProxy parent) throws TransactionFailure { ConfigBean configBean = (ConfigBean) Dom.unwrap(self); // ensure the parent is locked Transaction t = Transaction.getTransaction(parent); if (t==null) { throw new TransactionFailure("Must use a locked parent config object for copying new config object"); } ConfigBean copy = configBean.copy(configBean.parent()); return t.enroll(copy.createProxy()); }
public static ConfigBeanProxy deepCopy(ConfigBeanProxy self, ConfigBeanProxy parent) throws TransactionFailure { ConfigBean configBean = (ConfigBean) Dom.unwrap(self); // ensure the parent is locked Transaction t = Transaction.getTransaction(parent); if (t==null) { throw new TransactionFailure("Must use a locked parent config object for copying new config object"); } ConfigBean copy = configBean.copy(configBean.parent()); return t.enroll(copy.createProxy()); }