Search in sources :

Example 1 with WriteableBeanDatabase

use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.

the class DynamicChangeInfo method startOrContinueChange.

/**
 * Write lock MUST be held!
 *
 * @return
 */
public XmlDynamicChange startOrContinueChange(BaseHK2JAXBBean participant) {
    changeDepth++;
    if (participant != null) {
        participants.add(participant);
    }
    if (dynamicChange != null)
        return dynamicChange;
    globalSuccess = true;
    DynamicConfiguration change = null;
    DynamicConfiguration systemChange = null;
    if (dynamicService != null) {
        systemChange = dynamicService.createDynamicConfiguration();
        if (advertiseInLocator) {
            change = systemChange;
        }
    }
    WriteableBeanDatabase wbd = null;
    if (hub != null && advertiseInHub) {
        wbd = hub.getWriteableDatabaseCopy();
        wbd.setCommitMessage(new XmlHubCommitMessage() {
        });
        if (systemChange != null) {
            systemChange.registerTwoPhaseResources(wbd.getTwoPhaseResource());
        // Now the hub transaction is tied to the registry transaction
        }
    }
    dynamicChange = new XmlDynamicChange(wbd, change, systemChange);
    return dynamicChange;
}
Also used : XmlHubCommitMessage(org.glassfish.hk2.xml.api.XmlHubCommitMessage) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) WriteableBeanDatabase(org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase)

Example 2 with WriteableBeanDatabase

use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.

the class DynamicChangeInfo method endOrDeferChange.

/**
 * Write lock MUST be held!
 *
 * @return
 */
public void endOrDeferChange(boolean success) throws MultiException {
    changeDepth--;
    if (changeDepth < 0)
        changeDepth = 0;
    if (!success)
        globalSuccess = false;
    if (changeDepth > 0)
        return;
    List<BaseHK2JAXBBean> localParticipants = new ArrayList<BaseHK2JAXBBean>(participants);
    participants.clear();
    XmlDynamicChange localDynamicChange = dynamicChange;
    dynamicChange = null;
    if (localDynamicChange == null)
        return;
    ConstraintViolationException validationException = null;
    if (globalSuccess && (validator != null) && (root != null) && (root.getRoot() != null)) {
        // Validate root if validation is on
        Set<ConstraintViolation<Object>> violations = validator.<Object>validate(root.getRoot());
        if (violations != null && !violations.isEmpty()) {
            validationException = new ConstraintViolationException(violations);
        }
    }
    if (!globalSuccess || (validationException != null)) {
        for (BaseHK2JAXBBean participant : localParticipants) {
            participant.__rollbackChange();
        }
        if (validationException != null) {
            throw new MultiException(validationException);
        }
        return;
    }
    for (BaseHK2JAXBBean participant : localParticipants) {
        participant.__activateChange();
    }
    DynamicConfiguration systemChange = localDynamicChange.getSystemDynamicConfiguration();
    WriteableBeanDatabase wbd = localDynamicChange.getBeanDatabase();
    if (systemChange == null && wbd != null) {
        // Weird case, can it happen?
        wbd.commit(new XmlHubCommitMessage() {
        });
        return;
    }
    if (systemChange == null)
        return;
    // Can definitely throw, for example if a listener fails
    systemChange.commit();
}
Also used : XmlHubCommitMessage(org.glassfish.hk2.xml.api.XmlHubCommitMessage) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) BaseHK2JAXBBean(org.glassfish.hk2.xml.jaxb.internal.BaseHK2JAXBBean) ConstraintViolation(jakarta.validation.ConstraintViolation) ArrayList(java.util.ArrayList) ConstraintViolationException(jakarta.validation.ConstraintViolationException) MultiException(org.glassfish.hk2.api.MultiException) WriteableBeanDatabase(org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase)

Example 3 with WriteableBeanDatabase

use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.

the class NegativeHubTest method testRemoveInstanceWithNullKey.

/**
 * Null as name for addInstance
 */
@Test(expected = IllegalArgumentException.class)
public void testRemoveInstanceWithNullKey() {
    WriteableBeanDatabase wbd = hub.getWriteableDatabaseCopy();
    WriteableType wt = wbd.addType(ERROR_TYPE);
    wt.removeInstance(null);
}
Also used : WriteableType(org.glassfish.hk2.configuration.hub.api.WriteableType) WriteableBeanDatabase(org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase) Test(org.junit.Test)

Example 4 with WriteableBeanDatabase

use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.

the class NegativeHubTest method testAddInstanceWithNullBoth.

/**
 * Null as key and bean for addInstance
 */
@Test(expected = IllegalArgumentException.class)
public void testAddInstanceWithNullBoth() {
    WriteableBeanDatabase wbd = hub.getWriteableDatabaseCopy();
    WriteableType wt = wbd.addType(ERROR_TYPE);
    wt.addInstance(null, null);
}
Also used : WriteableType(org.glassfish.hk2.configuration.hub.api.WriteableType) WriteableBeanDatabase(org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase) Test(org.junit.Test)

Example 5 with WriteableBeanDatabase

use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.

the class NegativeHubTest method testModifyInstanceWithNullValue.

/**
 * Null as bean for modifyInstance
 */
@Test(expected = IllegalArgumentException.class)
public void testModifyInstanceWithNullValue() {
    WriteableBeanDatabase wbd = hub.getWriteableDatabaseCopy();
    WriteableType wt = wbd.addType(ERROR_TYPE);
    wt.modifyInstance(ERROR_NAME, null);
}
Also used : WriteableType(org.glassfish.hk2.configuration.hub.api.WriteableType) WriteableBeanDatabase(org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase) Test(org.junit.Test)

Aggregations

WriteableBeanDatabase (org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase)70 WriteableType (org.glassfish.hk2.configuration.hub.api.WriteableType)50 Test (org.junit.Test)31 HashMap (java.util.HashMap)11 Change (org.glassfish.hk2.configuration.hub.api.Change)10 Type (org.glassfish.hk2.configuration.hub.api.Type)10 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)8 PropertyChangeEvent (java.beans.PropertyChangeEvent)6 BaseHK2JAXBBean (org.glassfish.hk2.xml.jaxb.internal.BaseHK2JAXBBean)5 Map (java.util.Map)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 Hub (org.glassfish.hk2.configuration.hub.api.Hub)4 Instance (org.glassfish.hk2.configuration.hub.api.Instance)4 XmlHubCommitMessage (org.glassfish.hk2.xml.api.XmlHubCommitMessage)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 ServiceLocatorGeneratorImpl (org.jvnet.hk2.external.generator.ServiceLocatorGeneratorImpl)3 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2