Search in sources :

Example 1 with State

use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.

the class AbstractServlet method getConfiguredObjectFinder.

protected final ConfiguredObjectFinder getConfiguredObjectFinder(final ConfiguredObject<?> root) {
    ConfiguredObjectFinder finder = _configuredObjectFinders.get(root);
    if (finder == null) {
        finder = new ConfiguredObjectFinder(root);
        final ConfiguredObjectFinder existingValue = _configuredObjectFinders.putIfAbsent(root, finder);
        if (existingValue != null) {
            finder = existingValue;
        } else {
            final AbstractConfigurationChangeListener deletionListener = new AbstractConfigurationChangeListener() {

                @Override
                public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
                    if (newState == State.DELETED) {
                        _configuredObjectFinders.remove(root);
                    }
                }
            };
            root.addChangeListener(deletionListener);
            if (root.getState() == State.DELETED) {
                _configuredObjectFinders.remove(root);
                root.removeChangeListener(deletionListener);
            }
        }
    }
    return finder;
}
Also used : State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFinder(org.apache.qpid.server.model.ConfiguredObjectFinder) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 2 with State

use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.

the class AbstractConfiguredObjectTest method testSuccessfulStateTransitionInvokesListener.

public void testSuccessfulStateTransitionInvokesListener() throws Exception {
    TestConfiguredObject parent = new TestConfiguredObject("parent");
    parent.create();
    final AtomicReference<State> newState = new AtomicReference<>();
    final AtomicInteger callCounter = new AtomicInteger();
    parent.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(final ConfiguredObject<?> object, final State old, final State state) {
            super.stateChanged(object, old, state);
            callCounter.incrementAndGet();
            newState.set(state);
        }
    });
    parent.delete();
    assertEquals(State.DELETED, newState.get());
    assertEquals(1, callCounter.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) State(org.apache.qpid.server.model.State) AtomicReference(java.util.concurrent.atomic.AtomicReference) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 3 with State

use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.

the class AbstractConfiguredObjectTest method XtestUnsuccessfulStateTransitionDoesNotInvokesListener.

// TODO - not sure if I want to keep the state transition methods on delete
public void XtestUnsuccessfulStateTransitionDoesNotInvokesListener() throws Exception {
    final IllegalStateTransitionException expectedException = new IllegalStateTransitionException("This test fails the state transition.");
    TestConfiguredObject parent = new TestConfiguredObject("parent") {

        @Override
        protected ListenableFuture<Void> doDelete() {
            throw expectedException;
        }
    };
    parent.create();
    final AtomicInteger callCounter = new AtomicInteger();
    parent.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(final ConfiguredObject<?> object, final State old, final State state) {
            super.stateChanged(object, old, state);
            callCounter.incrementAndGet();
        }

        @Override
        public void attributeSet(ConfiguredObject<?> object, String attributeName, Object oldAttributeValue, Object newAttributeValue) {
            super.attributeSet(object, attributeName, oldAttributeValue, newAttributeValue);
            callCounter.incrementAndGet();
        }
    });
    try {
        parent.delete();
        fail("Exception not thrown.");
    } catch (RuntimeException e) {
        assertSame("State transition threw unexpected exception.", expectedException, e);
    }
    assertEquals(0, callCounter.get());
    assertEquals(State.ACTIVE, parent.getDesiredState());
    assertEquals(State.ACTIVE, parent.getState());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 4 with State

use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.

the class ManagementModeStoreHandlerTest method virtualHostEntryQuiescedStatusTestImpl.

private void virtualHostEntryQuiescedStatusTestImpl(boolean mmQuiesceVhosts) {
    UUID virtualHostId = UUID.randomUUID();
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(VirtualHost.TYPE, "STANDARD");
    final ConfiguredObjectRecord virtualHost = new ConfiguredObjectRecordImpl(virtualHostId, VirtualHost.class.getSimpleName(), attributes, Collections.singletonMap(Broker.class.getSimpleName(), _root.getId()));
    final ArgumentCaptor<ConfiguredObjectRecordHandler> recovererArgumentCaptor = ArgumentCaptor.forClass(ConfiguredObjectRecordHandler.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            ConfiguredObjectRecordHandler recoverer = recovererArgumentCaptor.getValue();
            recoverer.handle(_root);
            recoverer.handle(_portEntry);
            recoverer.handle(virtualHost);
            return false;
        }
    }).when(_store).openConfigurationStore(recovererArgumentCaptor.capture());
    State expectedState = mmQuiesceVhosts ? State.QUIESCED : null;
    if (mmQuiesceVhosts) {
        _systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_QUIESCE_VIRTUAL_HOSTS, mmQuiesceVhosts);
    }
    _handler = createManagementModeStoreHandler();
    _handler.init(_systemConfig);
    Collection<ConfiguredObjectRecord> records = openAndGetRecords();
    ConfiguredObjectRecord hostEntry = getEntry(records, virtualHostId);
    Map<String, Object> hostAttributes = new HashMap<String, Object>(hostEntry.getAttributes());
    assertEquals("Unexpected state", expectedState, hostAttributes.get(VirtualHost.STATE));
    hostAttributes.remove(VirtualHost.STATE);
    assertEquals("Unexpected attributes", attributes, hostAttributes);
}
Also used : HashMap(java.util.HashMap) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ConfiguredObjectRecordImpl(org.apache.qpid.server.store.ConfiguredObjectRecordImpl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) VirtualHost(org.apache.qpid.server.model.VirtualHost) UUID(java.util.UUID) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 5 with State

use of org.apache.qpid.server.model.State in project qpid-broker-j by apache.

the class AbstractKeyStore method initializeExpiryChecking.

protected void initializeExpiryChecking() {
    int checkFrequency = getCertificateExpiryCheckFrequency();
    if (getBroker().getState() == State.ACTIVE) {
        _checkExpiryTaskFuture = getBroker().scheduleHouseKeepingTask(checkFrequency, TimeUnit.DAYS, new Runnable() {

            @Override
            public void run() {
                checkCertificateExpiry();
            }
        });
    } else {
        final int frequency = checkFrequency;
        getBroker().addChangeListener(new AbstractConfigurationChangeListener() {

            @Override
            public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
                if (newState == State.ACTIVE) {
                    _checkExpiryTaskFuture = getBroker().scheduleHouseKeepingTask(frequency, TimeUnit.DAYS, () -> checkCertificateExpiry());
                    getBroker().removeChangeListener(this);
                }
            }
        });
    }
}
Also used : State(org.apache.qpid.server.model.State) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Aggregations

State (org.apache.qpid.server.model.State)13 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)9 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)7 Durability (com.sleepycat.je.Durability)3 File (java.io.File)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ConfigurationChangeListener (org.apache.qpid.server.model.ConfigurationChangeListener)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NodeState (com.sleepycat.je.rep.NodeState)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)1 IllegalStateTransitionException (org.apache.qpid.server.model.IllegalStateTransitionException)1 VirtualHost (org.apache.qpid.server.model.VirtualHost)1 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)1 ConfiguredObjectRecordImpl (org.apache.qpid.server.store.ConfiguredObjectRecordImpl)1 ConfiguredObjectRecordHandler (org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)1