Search in sources :

Example 1 with AcsJEventSubscriptionEx

use of alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx in project ACS by ACS-Community.

the class NCSubscriberTest method testAddSubscription.

/**
	 */
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testAddSubscription() throws Exception {
    // Invalid receiver (returns null)
    try {
        m_subscriber.addSubscription(new EventReceiver1() {

            public Class<statusBlockEvent1> getEventType() {
                return null;
            }
        });
        fail("Event receiver is invalid, as it returns a null event type");
    } catch (AcsJEventSubscriptionEx e) {
    }
    // Invalid receiver (returns String.class)
    try {
        m_subscriber.addSubscription(new Callback() {

            public void receive(Object event, EventDescription eventDescrip) {
            }

            public Class getEventType() {
                return String.class;
            }
        });
        fail("Event receiver is invalid, as it returns a java.lang.String as the event type");
    } catch (AcsJEventSubscriptionEx e) {
    }
    // Several receiver subscriptions for the same type overwrite the previous one
    m_subscriber.addSubscription(new EventReceiver1());
    m_subscriber.addSubscription(new EventReceiver1());
    m_subscriber.addSubscription(new EventReceiver1());
    m_subscriber.addSubscription(new EventReceiver1());
    assertEquals(1, m_subscriber.subscriptionsFilters.size());
    assertEquals(1, m_subscriber.getNumberOfReceivers());
    assertFalse(m_subscriber.hasGenericReceiver());
    assertEquals(2, m_subscriber.proxySupplier.get_all_filters().length);
    m_subscriber.addSubscription(new EventReceiver2());
    m_subscriber.addSubscription(new EventReceiver2());
    m_subscriber.addSubscription(new EventReceiver2());
    m_subscriber.addSubscription(new EventReceiver2());
    assertEquals(2, m_subscriber.subscriptionsFilters.size());
    assertEquals(2, m_subscriber.getNumberOfReceivers());
    assertFalse(m_subscriber.hasGenericReceiver());
    assertEquals(3, m_subscriber.proxySupplier.get_all_filters().length);
    m_subscriber.addGenericSubscription(new GenericEventReceiver());
    m_subscriber.addGenericSubscription(new GenericEventReceiver());
    m_subscriber.addGenericSubscription(new GenericEventReceiver());
    m_subscriber.addGenericSubscription(new GenericEventReceiver());
    assertEquals(3, m_subscriber.subscriptionsFilters.size());
    assertEquals(2, m_subscriber.getNumberOfReceivers());
    assertTrue(m_subscriber.hasGenericReceiver());
    assertEquals(4, m_subscriber.proxySupplier.get_all_filters().length);
}
Also used : AcsJEventSubscriptionEx(alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx) GenericCallback(alma.acs.nc.AcsEventSubscriber.GenericCallback) Callback(alma.acs.nc.AcsEventSubscriber.Callback) EventDescription(alma.acsnc.EventDescription) Test(org.junit.Test)

Example 2 with AcsJEventSubscriptionEx

use of alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx in project ACS by ACS-Community.

the class NCSubscriber method notifyFirstSubscription.

/**
	 * Adds a filter on the server-side supplier proxy that lets the given event type pass through.
	 * <p>
	 * Note that we derive the event type name from the simple class name of <code>struct</code>, 
	 * as done in other parts of ACS, which requires IDL event structs to have globally unique names 
	 * across IDL name spaces.
	 * <p>
	 * If <code>structClass</code> is <code>null</code> (generic subscription), 
	 * then "<code>*</code>" is used as the event type name,
	 * which in ETCL is understood as a wildcard for all event type names. 
	 * 
	 * @param structClass
	 * @throws AcsJEventSubscriptionEx
	 */
@Override
protected void notifyFirstSubscription(Class<?> structClass) throws AcsJEventSubscriptionEx {
    String eventTypeNameShort = (structClass == null ? "*" : structClass.getSimpleName());
    try {
        int filterId = addFilter(eventTypeNameShort);
        subscriptionsFilters.put(eventTypeNameShort, filterId);
    } catch (AcsJCORBAProblemEx e) {
        throw new AcsJEventSubscriptionEx(e);
    }
}
Also used : AcsJEventSubscriptionEx(alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx) AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)

Example 3 with AcsJEventSubscriptionEx

use of alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx in project ACS by ACS-Community.

the class AcsEventSubscriberImplBase method addSubscription.

@Override
public final <U extends T> void addSubscription(Callback<U> receiver) throws AcsJEventSubscriptionEx {
    Class<U> subscribedEventType = receiver.getEventType();
    if (subscribedEventType == null || !(eventType.isAssignableFrom(subscribedEventType))) {
        AcsJEventSubscriptionEx ex = new AcsJEventSubscriptionEx();
        ex.setContext("Receiver is returning a null or invalid event type. " + "Check the getEventType() method implementation and try again.");
        ex.setEventType(subscribedEventType == null ? "null" : subscribedEventType.getName());
        throw ex;
    }
    // First time we create the filter and set the receiver
    if (!receivers.containsKey(subscribedEventType)) {
        notifyFirstSubscription(subscribedEventType);
    }
    // After the filter is created, we just replace the corresponding receivers
    receivers.put(subscribedEventType, receiver);
}
Also used : AcsJEventSubscriptionEx(alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx)

Example 4 with AcsJEventSubscriptionEx

use of alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx in project ACS by ACS-Community.

the class AcsEventSubscriberImplBase method removeSubscription.

@Override
public final <U extends T> void removeSubscription(Class<U> structClass) throws AcsJEventSubscriptionEx {
    // Removing subscription from receivers list
    if (structClass != null) {
        if (receivers.containsKey(structClass)) {
            receivers.remove(structClass);
            notifySubscriptionRemoved(structClass);
        } else {
            AcsJEventSubscriptionEx ex = new AcsJEventSubscriptionEx();
            ex.setContext("Trying to unsubscribe from an event type not being subscribed to.");
            ex.setEventType(structClass.getName());
            throw ex;
        }
    } else {
        // Removing every type of event
        receivers.clear();
        notifyNoSubscription();
    }
}
Also used : AcsJEventSubscriptionEx(alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx)

Example 5 with AcsJEventSubscriptionEx

use of alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx in project ACS by ACS-Community.

the class AcsEventSubscriberImplBase method removeGenericSubscription.

/**
	 * Removes the generic receiver handler.
	 * 
	 * @throws AcsJCORBAProblemEx
	 */
@Override
public final void removeGenericSubscription() throws AcsJEventSubscriptionEx {
    if (genericReceiver == null) {
        AcsJEventSubscriptionEx ex = new AcsJEventSubscriptionEx();
        ex.setContext("Failed to remove generic subscription when not actually subscribed.");
        ex.setEventType("generic");
        throw ex;
    }
    notifySubscriptionRemoved(null);
    genericReceiver = null;
}
Also used : AcsJEventSubscriptionEx(alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx)

Aggregations

AcsJEventSubscriptionEx (alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx)7 Test (org.junit.Test)2 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)1 Callback (alma.acs.nc.AcsEventSubscriber.Callback)1 GenericCallback (alma.acs.nc.AcsEventSubscriber.GenericCallback)1 EventDescription (alma.acsnc.EventDescription)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 FilterNotFound (org.omg.CosNotifyFilter.FilterNotFound)1