Search in sources :

Example 16 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class ApplicationLifecycle method prepareAppConfigChanges.

// prepare application config change for later registering
// in the domain.xml
@Override
public Transaction prepareAppConfigChanges(final DeploymentContext context) throws TransactionFailure {
    final Properties appProps = context.getAppProps();
    final DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
    Transaction tx = null;
    Application app_w = null;
    if (deployParams.hotDeploy) {
        app_w = applications.getApplication(deployParams.name);
    }
    if (app_w == null) {
        try {
            tx = new Transaction();
            // prepare the application element
            ConfigBean newBean = ((ConfigBean) Dom.unwrap(applications)).allocate(Application.class);
            Application app = newBean.createProxy();
            app_w = tx.enroll(app);
            setInitialAppAttributes(app_w, deployParams, appProps, context);
        } catch (TransactionFailure e) {
            tx.rollback();
            throw e;
        } catch (Exception e) {
            tx.rollback();
            throw new TransactionFailure(e.getMessage(), e);
        }
    }
    context.addTransientAppMetaData(ServerTags.APPLICATION, app_w);
    return tx;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transaction(org.jvnet.hk2.config.Transaction) ConfigBean(org.jvnet.hk2.config.ConfigBean) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) MultiException(org.glassfish.hk2.api.MultiException) DeploymentException(org.glassfish.deployment.common.DeploymentException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

Example 17 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class DirectAccessTest method doTest.

public void doTest() throws TransactionFailure {
    NetworkConfig networkConfig = habitat.getService(NetworkConfig.class);
    final NetworkListener listener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
    final Http http = listener.findHttpProtocol().getHttp();
    ConfigBean config = (ConfigBean) ConfigBean.unwrap(http.getFileCache());
    ConfigBean config2 = (ConfigBean) ConfigBean.unwrap(http);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("max-age-seconds", "12543");
    configChanges.put("max-cache-size-bytes", "1200");
    Map<String, String> config2Changes = new HashMap<String, String>();
    config2Changes.put("http2-enabled", "false");
    changes.put(config, configChanges);
    changes.put(config2, config2Changes);
    JavaConfig javaConfig = habitat.getService(JavaConfig.class);
    ConfigBean javaConfigBean = (ConfigBean) ConfigBean.unwrap(javaConfig);
    Map<String, String> javaConfigChanges = new HashMap<String, String>();
    javaConfigChanges.put("jvm-options", "-XFooBar=false");
    changes.put(javaConfigBean, javaConfigChanges);
    getHabitat().<ConfigSupport>getService(ConfigSupport.class).apply(changes);
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) ConfigBean(org.jvnet.hk2.config.ConfigBean) Map(java.util.Map) HashMap(java.util.HashMap) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 18 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class DirectRemovalTest method doTest.

public void doTest() throws TransactionFailure {
    NetworkListeners listeners = habitat.getService(NetworkListeners.class);
    ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(listeners);
    for (NetworkListener listener : listeners.getNetworkListener()) {
        if (listener.getName().endsWith("http-listener-1")) {
            ConfigSupport.deleteChild(serviceBean, (ConfigBean) ConfigBean.unwrap(listener));
            break;
        }
    }
}
Also used : NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ConfigBean(org.jvnet.hk2.config.ConfigBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 19 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class ConfigTest method testGetConfigBean.

// @Test
public void testGetConfigBean() {
    SimpleConnector sc = habitat.getService(SimpleConnector.class);
    final EjbContainerAvailability ejb = sc.getEjbContainerAvailability();
    ConfigBean ejbConfigBean = (ConfigBean) ConfigBean.unwrap(ejb);
    assert (ejbConfigBean != null);
}
Also used : ConfigBean(org.jvnet.hk2.config.ConfigBean)

Example 20 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class WriteableView method removeNestedElements.

boolean removeNestedElements(Object object) {
    InvocationHandler h = Proxy.getInvocationHandler(object);
    if (!(h instanceof WriteableView)) {
        // h instanceof ConfigView
        ConfigBean bean = (ConfigBean) ((ConfigView) h).getMasterView();
        h = bean.getWriteableView();
        if (h == null) {
            ConfigBeanProxy writable;
            try {
                writable = currentTx.enroll((ConfigBeanProxy) object);
            } catch (TransactionFailure e) {
                // something is seriously wrong
                throw new RuntimeException(e);
            }
            h = Proxy.getInvocationHandler(writable);
        } else {
            // so oldValue was already processed
            return false;
        }
    }
    WriteableView writableView = (WriteableView) h;
    synchronized (writableView) {
        writableView.isDeleted = true;
    }
    boolean removed = false;
    for (Property property : writableView.bean.model.elements.values()) {
        if (property.isCollection()) {
            Object nested = writableView.getter(property, parameterizedType);
            ProtectedList<?> list = (ProtectedList<?>) nested;
            if (list.size() > 0) {
                list.clear();
                removed = true;
            }
        } else if (!property.isLeaf()) {
            // Element
            Object oldValue = writableView.getter(property, ConfigBeanProxy.class);
            if (oldValue != null) {
                writableView.setter(property, null, Dom.class);
                removed = true;
                removeNestedElements(oldValue);
            }
        }
    }
    return removed;
}
Also used : Property(org.jvnet.hk2.config.ConfigModel.Property)

Aggregations

ConfigBean (org.jvnet.hk2.config.ConfigBean)28 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)21 HashMap (java.util.HashMap)18 Map (java.util.Map)15 ConfigSupport (org.jvnet.hk2.config.ConfigSupport)12 Test (org.junit.Test)11 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)8 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)8 Property (org.jvnet.hk2.config.types.Property)8 PropertyVetoException (java.beans.PropertyVetoException)7 Method (java.lang.reflect.Method)5 ConstraintViolationException (javax.validation.ConstraintViolationException)5 Dom (org.jvnet.hk2.config.Dom)5 Cluster (com.sun.enterprise.config.serverbeans.Cluster)4 Domain (com.sun.enterprise.config.serverbeans.Domain)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)4 MultiException (org.glassfish.hk2.api.MultiException)4