/** * Executes some logic on some config beans protected by a transaction. * * @param code code to execute * @param objects config beans participating to the transaction * @return list of property change events * @throws TransactionFailure when the code did run successfully due to a * transaction exception */ public static Object apply(ConfigCode code, ConfigBeanProxy... objects) throws TransactionFailure { ConfigBean source = (ConfigBean) ConfigBean.unwrap(objects[0]); return source.getHabitat().<ConfigSupport>getService(ConfigSupport.class)._apply(code, objects); }
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 void deleteChild( final ConfigBean parent, final ConfigBean child) throws TransactionFailure { ConfigBeanProxy readableView = parent.getProxy(parent.getProxyType()); apply(new SingleConfigCode<ConfigBeanProxy>() { public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure { // remove the child from the parent. WriteableView writeableParent = (WriteableView) Proxy.getInvocationHandler(param); _deleteChild(parent, writeableParent, child); return child; } }, readableView); }
/** * 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 */ <T extends ConfigBeanProxy> T allocateProxy(Class<T> type) { return allocate(type).createProxy(type); }
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); }
/** * 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 Transaction prepareAppConfigChanges(final DeploymentContext context) throws TransactionFailure { final Properties appProps = context.getAppProps(); final DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class); Transaction t = new Transaction(); try { // prepare the application element ConfigBean newBean = ((ConfigBean)ConfigBean.unwrap(applications)).allocate(Application.class); Application app = newBean.createProxy(); Application app_w = t.enroll(app); setInitialAppAttributes(app_w, deployParams, appProps, context); context.addTransientAppMetaData(ServerTags.APPLICATION, app_w); } catch(TransactionFailure e) { t.rollback(); throw e; } catch (Exception e) { t.rollback(); throw new TransactionFailure(e.getMessage(), e); } return t; }
return; final ConfigBean child = (ConfigBean) ConfigBean.unwrap(target); ConfigBeanProxy parentProxy = child.parent().createProxy(); ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() { @Override "GenericDeleteCommand.transaction_exception", "Exception while deleting the configuration {0} :{1}", child.typeName(), e.getMessage()); result.failure(logger, msg);
throw new IllegalArgumentException("A " + master.getProxyType().getSimpleName() + " with the same key \"" + keyValue + "\" already exists in " + parent.getProxyType().getSimpleName() + " " + parent.getKey()) ; param = ((WriteableView) handler).getMasterView().createProxy( (Class<ConfigBeanProxy>) master.getImplementationClass()); for (ConfigBeanInterceptor interceptor : bean.getOptionalFeatures()) { interceptor.beforeChange(evt);
public void testGetConfigBean() { SimpleConnector sc = habitat.getService(SimpleConnector.class); final EjbContainerAvailability ejb = sc.getEjbContainerAvailability(); ConfigBean ejbConfigBean = (ConfigBean) ConfigBean.unwrap(ejb); assert(ejbConfigBean != null); }
/** * 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 properly constructed configuration object */ public ConfigBean allocate(Class<?> type) { return (ConfigBean) document.make(getHabitat(), null, this, document.buildModel(type)); }
public <T extends ConfigBeanProxy> Class<T> getProxyType() { return bean.getProxyType(); }
/** */ private ConfigBean getActualParent(final ConfigBean configBean) { ConfigBean parent = asConfigBean(configBean.parent()); if (parent == null) { if (!configBean.getProxyType().getName().endsWith("Domain")) { throw new IllegalStateException("WARNING: parent is null for " + configBean.getProxyType().getName() + ", see issue #10528"); } } return parent; }
ConfigBeanProxy parentProxy = child.parent().createProxy(); ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() { @Override "GenericDeleteCommand.transaction_exception", "Exception while deleting the configuration {0} :{1}", child.getImplementation(), e.getMessage()); result.failure(logger, msg);
@Override public ConfigBean make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, ConfigBean dom, ConfigModel configModel) { ConfigBean configBean = new ConfigBean(habitat,this, dom, configModel, xmlStreamReader); configBean.addInterceptor(Object.class, new OnDeleteCascade()); return configBean; } }
handleValidation(property, newValue); } catch(Exception v) { bean.getLock().unlock(); throw new RuntimeException(v); String siblingKey = sibling.getKey(); if (newValue.equals(siblingKey)) { bean.getLock().unlock(); throw new IllegalArgumentException( "Keys cannot be duplicate. Old value of this key " + Object oldValue = bean.getter(property, t); if (newValue instanceof ConfigBeanProxy) { ConfigView bean = (ConfigView) defaultView,property.xmlName(), oldValue, newValue); try { for (ConfigBeanInterceptor interceptor : bean.getOptionalFeatures()) { interceptor.beforeChange(evt); for (ConfigBeanInterceptor interceptor : bean.getOptionalFeatures()) { interceptor.afterChange(evt, System.currentTimeMillis());
/** * Returns a copy of itself providing the parent for the new copy. * * @param parent the parent instance for the cloned copy * @return the cloned copy */ @Override protected <T extends Dom> T copy(T parent) { return (T) new ConfigBean(this, parent); }
/** * Aborts this Transaction, reverting the state * * @param t the aborting transaction */ public synchronized void abort(Transaction t) { currentTx=null; bean.getLock().unlock(); changedAttributes.clear(); }
public WriteableView(ConfigBeanProxy readView) { this.bean = (ConfigBean) ((ConfigView) Proxy.getInvocationHandler(readView)).getMasterView(); this.defaultView = bean.createProxy(); changedAttributes = new HashMap<String, PropertyChangeEvent>(); changedCollections = new HashMap<String, ProtectedList>(); }
/** return true if the candidate is a descendent of the parent */ private boolean isDescendent(final ConfigBean candidate, final ConfigBean parent) { boolean isParent = false; Dom temp = candidate.parent(); while (temp != null) { if (temp == parent) { isParent = true; break; } temp = temp.parent(); } return isParent; }