Search in sources :

Example 1 with JMSTopicTransportManager

use of org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager in project eclipselink by eclipse-ee4j.

the class JMSTopicRemoteConnection method run.

/**
 * INTERNAL:
 * This method is used by local (listening) connection only.
 * The only way to exit the loop is to set isActive to false -
 * there should be no uncaught exceptions thrown from inside the loop.
 * The execution exits the loop either in case of exception in remove connection on error mode;
 * or by trasportManager.removeLocalConnection() call
 * (which calls connection.close(), which sets isActive to false).
 */
@Override
public void run() {
    JMSTopicTransportManager tm = (JMSTopicTransportManager) rcm.getTransportManager();
    rcm.logDebug("broadcast_connection_start_listening", getInfo());
    // indicates whether to create a new connection before exiting the thread.
    boolean shouldReconnect = false;
    // exception indicating that the received message is null.
    RuntimeException messageIsNullException = null;
    // Should never exit this loop because of an uncaught exception.
    while (isActive()) {
        try {
            Message message = subscriber.receive();
            // close method could have been called while subscriber.receive() was waiting.
            if (isActive()) {
                if (message == null) {
                    try {
                        // user has a chance to handle exception - for instance to ignore it.
                        rcm.handleException(RemoteCommandManagerException.errorJMSMessageIsNull());
                        // exception has been handled, go to the next iteration.
                        continue;
                    } catch (RuntimeException ex) {
                        messageIsNullException = ex;
                        // throw a dummy JMSException to get into catch block
                        throw new JMSException("");
                    }
                }
                // process the message and log a warning without throwing exception if there was exception.
                rcm.getServerPlatform().launchContainerRunnable(new JMSOnMessageHelper(message));
            }
        } catch (JMSException e) {
            // close method could have been called while subscriber.receive() was waiting.
            if (isActive()) {
                RemoteCommandManagerException rcmException;
                if (messageIsNullException != null) {
                    rcmException = RemoteCommandManagerException.errorReceivingJMSMessage(messageIsNullException);
                    messageIsNullException = null;
                } else {
                    rcmException = RemoteCommandManagerException.errorReceivingJMSMessage(e);
                }
                if (tm.shouldRemoveConnectionOnError()) {
                    shouldReconnect = true;
                    Object[] args = { getServiceId(), rcmException };
                    rcm.logWarning("drop_connection_on_error", args);
                    // after connection is closed isActive will return false.
                    tm.removeLocalConnection();
                } else {
                    try {
                        // user has a chance to handle exception:
                        // for instance to shut down the command manager.
                        rcm.handleException(rcmException);
                    } catch (RuntimeException ex) {
                        // Ignore the exception, sleep before going back to listening.
                        Object[] args = { toString(), rcmException, WAIT_ON_ERROR_RECEIVING_JMS_MESSAGE };
                        rcm.logWarning("broadcast_listening_sleep_on_error", args);
                        try {
                            Thread.sleep(WAIT_ON_ERROR_RECEIVING_JMS_MESSAGE);
                        } catch (InterruptedException interruptedEception) {
                        // Ignore
                        }
                    }
                }
            }
        }
    }
    // Out of the loop - that means close method has been called.
    rcm.logDebug("broadcast_connection_stop_listening", getInfo());
    if (isClosing()) {
        try {
            // There is no need to close the sessions, producers, and consumers of a closed TopicConnection.
            topicConnection.close();
        } catch (JMSException closeException) {
            Object[] args = { displayString, closeException };
            rcm.logWarning("broadcast_exception_thrown_when_attempting_to_close_connection", args);
        } finally {
            rcm.logDebug("broadcast_connection_closed", getInfo());
            state = STATE_CLOSED;
        }
    }
    if (shouldReconnect && !tm.getRemoteCommandManager().isStopped()) {
        try {
            tm.createLocalConnection();
        } catch (RemoteCommandManagerException ex) {
        // Ignore exception - user had a chance to handle it in createLocalConnection method:
        // for instance to change host url and create a new local connection.
        }
    }
}
Also used : RemoteCommandManagerException(org.eclipse.persistence.exceptions.RemoteCommandManagerException) JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager) Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) ObjectMessage(jakarta.jms.ObjectMessage) JMSException(jakarta.jms.JMSException)

Example 2 with JMSTopicTransportManager

use of org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager in project eclipselink by eclipse-ee4j.

the class JMSSetupHelper method createTransportManager.

@Override
protected void createTransportManager(RemoteCommandManager rcm) {
    JMSTopicTransportManager tm = new JMSTopicTransportManager(rcm);
    Properties props = new Properties();
    // should use the testing JNDI factory.
    props.setProperty(Context.INITIAL_CONTEXT_FACTORY, TEST_CONTEXT_FACTORY);
    // the testing JNDI doesn't require PROVIDER_URL property, but without it NPE is thrown
    props.setProperty(Context.PROVIDER_URL, "");
    tm.setRemoteContextProperties(props);
    // the testing JNDI doesn't require password, but without it NPE is thrown
    tm.setPassword("");
}
Also used : JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager) Properties(java.util.Properties)

Example 3 with JMSTopicTransportManager

use of org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager in project eclipselink by eclipse-ee4j.

the class RCMWithJmsTopicTest method verify.

@Override
public void verify() {
    RemoteCommandManager rcm = (RemoteCommandManager) ((AbstractSession) loadedSession).getCommandManager();
    JMSTopicTransportManager transportMgr = (JMSTopicTransportManager) rcm.getTransportManager();
    Vector errors = new Vector();
    if (!rcm.getChannel().equals("new_channel")) {
        errors.add("channel = " + rcm.getChannel());
    }
    if (!((AbstractSession) loadedSession).shouldPropagateChanges()) {
        errors.add("cache sync is not enable");
    }
    if (rcm.getTransportManager().shouldRemoveConnectionOnError()) {
        errors.add("remove connection on error");
    }
    if (!rcm.shouldPropagateAsynchronously()) {
        errors.add("send mode is synchronous but should always be asynchronous by default.");
    }
    // naming services
    if (transportMgr.getTopicHostUrl() == null || !(transportMgr.getTopicHostUrl().equals("ormi://jms_topic_host"))) {
        errors.add("topic-host-url = " + transportMgr.getTopicHostUrl());
    }
    if (!(transportMgr.getTopicConnectionFactoryName().equals("test-topic-connection-factory-name"))) {
        errors.add("test-topic-connection-factory-name = " + transportMgr.getTopicConnectionFactoryName());
    }
    if (!(transportMgr.getTopicName().equals("test-topic-name"))) {
        errors.add("test-topic-name = " + transportMgr.getTopicName());
    }
    if (transportMgr.getTopicHostUrl() == null || !(transportMgr.getTopicHostUrl().equals("ormi://jms_topic_host"))) {
        errors.add("topic-host-url = " + transportMgr.getTopicHostUrl());
    }
    if (!rcm.getUrl().equals("ormi://jms_topic_host")) {
        errors.add("Url = " + rcm.getUrl());
    }
    String userName = (String) transportMgr.getRemoteContextProperties().get(Context.SECURITY_PRINCIPAL);
    if (userName == null || !userName.equals("new_user_name")) {
        errors.add("user name = " + userName);
    }
    String password = (String) transportMgr.getRemoteContextProperties().get(Context.SECURITY_CREDENTIALS);
    // decrypt password using default encryption
    password = new SecurableObjectHolder().getSecurableObject().decryptPassword(password);
    if (password == null || !password.equals("new_password")) {
        errors.add("password = " + password);
    }
    String contextFactory = (String) transportMgr.getRemoteContextProperties().get(Context.INITIAL_CONTEXT_FACTORY);
    if (contextFactory == null || !contextFactory.equals("new_initial_context_factory_name")) {
        errors.add("initial context factory name = " + contextFactory);
    }
    // extra properties
    String propertyValue1 = (String) transportMgr.getRemoteContextProperties().get("name1");
    String propertyValue2 = (String) transportMgr.getRemoteContextProperties().get("name2");
    if (propertyValue1 == null || !propertyValue1.equals("value1")) {
        errors.add("extra property name =  name1, value = " + propertyValue1);
    }
    if (propertyValue2 == null || !propertyValue2.equals("value2")) {
        errors.add("extra property name =  name2, value = " + propertyValue2);
    }
    if (!errors.isEmpty()) {
        String errorString = "The following RCM elements do not match their expected values:";
        for (Enumeration enumtr = errors.elements(); enumtr.hasMoreElements(); ) {
            errorString += "\n   " + enumtr.nextElement();
        }
        throw new TestErrorException(errorString);
    }
}
Also used : Enumeration(java.util.Enumeration) JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager) SecurableObjectHolder(org.eclipse.persistence.internal.security.SecurableObjectHolder) RemoteCommandManager(org.eclipse.persistence.sessions.coordination.RemoteCommandManager) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) Vector(java.util.Vector)

Example 4 with JMSTopicTransportManager

use of org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager in project eclipselink by eclipse-ee4j.

the class SessionsFactory method buildJMSTopicTransportManagerConfig.

/**
 * INTERNAL:
 */
protected void buildJMSTopicTransportManagerConfig(JMSTopicTransportManagerConfig tmConfig, RemoteCommandManager rcm) {
    JMSTopicTransportManager tm = new JMSTopicTransportManager(rcm);
    // Set the transport manager. This will initialize the DiscoveryManager
    rcm.setTransportManager(tm);
    processJMSTransportManagerConfig(tmConfig, tm);
}
Also used : JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager)

Example 5 with JMSTopicTransportManager

use of org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method updateCacheCoordination.

/**
 * Configure cache coordination using properties.
 */
protected void updateCacheCoordination(Map m, ClassLoader loader) {
    String protocol = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_PROTOCOL, m, this.session);
    String value = "";
    String property = "";
    try {
        if (protocol != null) {
            RemoteCommandManager rcm = new RemoteCommandManager(this.session);
            if (protocol.equalsIgnoreCase(CacheCoordinationProtocol.JGROUPS)) {
                property = PersistenceUnitProperties.COORDINATION_PROTOCOL;
                value = "org.eclipse.persistence.sessions.coordination.jgroups.JGroupsTransportManager";
                // Avoid compile and runtime dependency.
                Class<?> transportClass = findClassForProperty(value, PersistenceUnitProperties.COORDINATION_PROTOCOL, loader);
                TransportManager transport = (TransportManager) transportClass.getConstructor().newInstance();
                rcm.setTransportManager(transport);
                String config = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_JGROUPS_CONFIG, m, this.session);
                if (config != null) {
                    transport.setConfig(config);
                }
            } else if (protocol.equalsIgnoreCase(CacheCoordinationProtocol.JMS) || protocol.equalsIgnoreCase(CacheCoordinationProtocol.JMSPublishing)) {
                JMSPublishingTransportManager transport = null;
                if (protocol.equalsIgnoreCase(CacheCoordinationProtocol.JMS)) {
                    transport = new JMSTopicTransportManager(rcm);
                } else {
                    transport = new JMSPublishingTransportManager(rcm);
                }
                rcm.setTransportManager(transport);
                String host = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_JMS_HOST, m, this.session);
                if (host != null) {
                    transport.setTopicHostUrl(host);
                }
                String topic = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_JMS_TOPIC, m, this.session);
                if (topic != null) {
                    transport.setTopicName(topic);
                }
                String factory = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_JMS_FACTORY, m, this.session);
                if (factory != null) {
                    transport.setTopicConnectionFactoryName(factory);
                }
                String reuse_publisher = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_JMS_REUSE_PUBLISHER, m, this.session);
                if (reuse_publisher != null) {
                    transport.setShouldReuseJMSTopicPublisher(reuse_publisher.equalsIgnoreCase("true"));
                }
            } else if (protocol.equalsIgnoreCase(CacheCoordinationProtocol.RMI) || protocol.equalsIgnoreCase(CacheCoordinationProtocol.RMIIIOP)) {
                if (protocol.equalsIgnoreCase(CacheCoordinationProtocol.RMIIIOP)) {
                    ((RMITransportManager) rcm.getTransportManager()).setIsRMIOverIIOP(true);
                }
                // Default protocol.
                String delay = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_RMI_ANNOUNCEMENT_DELAY, m, this.session);
                property = PersistenceUnitProperties.COORDINATION_RMI_ANNOUNCEMENT_DELAY;
                value = delay;
                if (delay != null) {
                    rcm.getDiscoveryManager().setAnnouncementDelay(Integer.parseInt(delay));
                }
                String multicast = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_RMI_MULTICAST_GROUP, m, this.session);
                if (multicast != null) {
                    rcm.getDiscoveryManager().setMulticastGroupAddress(multicast);
                }
                String port = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_RMI_MULTICAST_GROUP_PORT, m, this.session);
                property = PersistenceUnitProperties.COORDINATION_RMI_MULTICAST_GROUP_PORT;
                value = port;
                if (port != null) {
                    rcm.getDiscoveryManager().setMulticastPort(Integer.parseInt(port));
                }
                String timeToLive = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_RMI_PACKET_TIME_TO_LIVE, m, this.session);
                property = PersistenceUnitProperties.COORDINATION_RMI_PACKET_TIME_TO_LIVE;
                value = timeToLive;
                if (timeToLive != null) {
                    rcm.getDiscoveryManager().setPacketTimeToLive(Integer.parseInt(timeToLive));
                }
                String url = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_RMI_URL, m, this.session);
                if (url != null) {
                    rcm.setUrl(url);
                }
            } else {
                property = PersistenceUnitProperties.COORDINATION_PROTOCOL;
                value = protocol;
                Class<?> transportClass = findClassForProperty(protocol, PersistenceUnitProperties.COORDINATION_PROTOCOL, loader);
                rcm.setTransportManager((TransportManager) transportClass.getConstructor().newInstance());
            }
            String serializer = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_SERIALIZER, m, this.session);
            if (serializer != null) {
                property = PersistenceUnitProperties.COORDINATION_SERIALIZER;
                value = serializer;
                Class<?> transportClass = findClassForProperty(serializer, PersistenceUnitProperties.COORDINATION_SERIALIZER, loader);
                rcm.setSerializer((Serializer) transportClass.getConstructor().newInstance());
            }
            String naming = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_NAMING_SERVICE, m, this.session);
            if (naming != null) {
                if (naming.equalsIgnoreCase("jndi")) {
                    rcm.getTransportManager().setNamingServiceType(TransportManager.JNDI_NAMING_SERVICE);
                } else if (naming.equalsIgnoreCase("rmi")) {
                    rcm.getTransportManager().setNamingServiceType(TransportManager.REGISTRY_NAMING_SERVICE);
                }
            }
            String user = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_JNDI_USER, m, this.session);
            if (user != null) {
                rcm.getTransportManager().setUserName(user);
            }
            String password = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_JNDI_PASSWORD, m, this.session);
            if (password != null) {
                rcm.getTransportManager().setPassword(password);
            }
            String context = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_JNDI_CONTEXT, m, this.session);
            if (context != null) {
                rcm.getTransportManager().setInitialContextFactoryName(context);
            }
            String removeOnError = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_REMOVE_CONNECTION, m, this.session);
            if (removeOnError != null) {
                rcm.getTransportManager().setShouldRemoveConnectionOnError(removeOnError.equalsIgnoreCase("true"));
            }
            String asynch = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_ASYNCH, m, this.session);
            if (asynch != null) {
                rcm.setShouldPropagateAsynchronously(asynch.equalsIgnoreCase("true"));
            }
            String threadPoolSize = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_THREAD_POOL_SIZE, m, this.session);
            property = PersistenceUnitProperties.COORDINATION_THREAD_POOL_SIZE;
            value = threadPoolSize;
            if (threadPoolSize != null) {
                this.session.getServerPlatform().setThreadPoolSize(Integer.parseInt(threadPoolSize));
            }
            String channel = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.COORDINATION_CHANNEL, m, this.session);
            if (channel != null) {
                rcm.setChannel(channel);
            }
            this.session.setCommandManager(rcm);
            this.session.setShouldPropagateChanges(true);
        }
    } catch (ReflectiveOperationException | NumberFormatException exception) {
        this.session.handleException(ValidationException.invalidValueForProperty(value, property, exception));
    }
}
Also used : RMITransportManager(org.eclipse.persistence.sessions.coordination.rmi.RMITransportManager) JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager) RemoteCommandManager(org.eclipse.persistence.sessions.coordination.RemoteCommandManager) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) JMSTopicTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager) JMSPublishingTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSPublishingTransportManager) TransportManager(org.eclipse.persistence.sessions.coordination.TransportManager) RMITransportManager(org.eclipse.persistence.sessions.coordination.rmi.RMITransportManager) JMSPublishingTransportManager(org.eclipse.persistence.sessions.coordination.jms.JMSPublishingTransportManager)

Aggregations

JMSTopicTransportManager (org.eclipse.persistence.sessions.coordination.jms.JMSTopicTransportManager)5 RemoteCommandManager (org.eclipse.persistence.sessions.coordination.RemoteCommandManager)2 BytesMessage (jakarta.jms.BytesMessage)1 JMSException (jakarta.jms.JMSException)1 Message (jakarta.jms.Message)1 ObjectMessage (jakarta.jms.ObjectMessage)1 Enumeration (java.util.Enumeration)1 Properties (java.util.Properties)1 Vector (java.util.Vector)1 RemoteCommandManagerException (org.eclipse.persistence.exceptions.RemoteCommandManagerException)1 EntityManagerFactoryProvider.getConfigPropertyAsString (org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)1 SecurableObjectHolder (org.eclipse.persistence.internal.security.SecurableObjectHolder)1 TransportManager (org.eclipse.persistence.sessions.coordination.TransportManager)1 JMSPublishingTransportManager (org.eclipse.persistence.sessions.coordination.jms.JMSPublishingTransportManager)1 RMITransportManager (org.eclipse.persistence.sessions.coordination.rmi.RMITransportManager)1 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)1