Search in sources :

Example 1 with RemoteBeanInterface

use of org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface in project quickstart by wildfly.

the class RemoteBeanCaller method directLookupStatelessBeanOverEjbRemotingCall.

/**
 * <p>
 * The method calls the remote EJB {@link Stateless} endpoint.<br/>
 * The invocation runs over EJB remoting where first call is run over HTTP,
 * then the HTTP upgrade requests the change to remoting protocol
 * </p>
 * <p>
 * To lookup the remote endpoint is used direct definition of the hostname, port and credentials
 * here in code. More specifically at time when {@link javax.naming.InitialContext} is defined,
 * see {@link RemoteLookupHelper#lookupRemoteEJBDirect(String, Class, boolean, String, int, String, String, boolean)}.
 * </p>
 * <p>
 * For details on the call processing see {@link #remoteOutboundStatelessBeanCall()}.
 * </p>
 *
 * @return list of strings as return values from the remote beans,
 *         in this case the return values are hostname and the jboss node names of the remote application server
 * @throws NamingException when remote lookup fails
 */
public List<String> directLookupStatelessBeanOverEjbRemotingCall() throws NamingException {
    log.debugf("Calling direct lookup with transaction to StatelessBean.successOnCall()");
    String remoteHost = System.getProperty("remote.server.host");
    int remotePort = Integer.getInteger("remote.server.port", 0);
    String remoteUsername = System.getProperty("remote.server.username");
    String remotePassword = System.getProperty("remote.server.password");
    RemoteBeanInterface bean = RemoteLookupHelper.lookupRemoteEJBDirect("StatelessBean", RemoteBeanInterface.class, false, remoteHost, remotePort, remoteUsername, remotePassword, false);
    return Arrays.asList(bean.successOnCall(), bean.successOnCall());
}
Also used : RemoteBeanInterface(org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface)

Example 2 with RemoteBeanInterface

use of org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface in project quickstart by wildfly.

the class RemoteBeanCaller method remoteOutboundStatelessBeanFail.

/**
 * <p>
 * The method calls the remote EJB {@link Stateless} endpoint.
 * </p>
 * <p>
 * To lookup the remote endpoint is used remote outbound connection defined in the <code>standalone.xml</code> configuration file.
 * The deployment links to the configuration by descriptor <code>WEB-INF/jboss-ejb-client.xml</code>.
 * </p>
 *
 * <p>
 * The method demonstrates the need of transaction recovery processing in case of some types of failures.
 * This one simulates an intermittent network failure happening on finishing the remote transaction.
 * </p>
 * <p>
 * The failure is invoked at time when transaction is decided to by committed by the two-phase protocol.
 * The remote call returns success despite the fact the remote server has not closed all the resources with commit.
 * The first attempt to commit fails and it's then the responsibility of recovery manager to finish
 * this transaction with another attempt of committing the remote transaction.
 * </p>
 * <p>
 * The recovery manager runs periodically, by default every 2 minutes. For making the recovery faster
 * we may force the recovery to be processed. This could be done if the recovery listener is enabled
 * (see <code>remote-configuration.cli</code> script). Then it's possible to send command 'SCAN'
 * to socket at port <code>4712</code>). The unfinished transaction is then finished.
 * </p>
 *
 * @return hostname of server as String that the invocation goes to
 * @throws NamingException when remote lookup fails
 */
public String remoteOutboundStatelessBeanFail() throws NamingException {
    log.debugf("Calling with failure to StatelessBean.failOnCall()");
    em.persist(new CallerUser("Fell", "Rider"));
    RemoteBeanInterface bean = RemoteLookupHelper.lookupRemoteEJBOutbound("StatelessBean", RemoteBeanInterface.class, false);
    return bean.failOnCall();
}
Also used : CallerUser(org.jboss.as.quickstarts.ejb.entity.CallerUser) RemoteBeanInterface(org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface)

Example 3 with RemoteBeanInterface

use of org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface in project quickstart by wildfly.

the class RemoteBeanCaller method remoteOutboundStatelessNoTxBeanCall.

/**
 * <p>
 * The method calls the remote EJB {@link Stateless} endpoint.
 * </p>
 * <p>
 * To lookup the remote endpoint is used remote outbound connection defined in the <code>standalone.xml</code> configuration file.
 * The deployment links to the configuration by descriptor <code>WEB-INF/jboss-ejb-client.xml</code>.
 * </p>
 *
 * <p>
 * The demonstration shows what happens when several subsequent calls are run while no transaction is started.
 * With one remote server all requests go to that one instance of <code>server2</code>.
 * It makes a difference if there are two (or more) remote servers clustered (<code>server2</code> is run in HA of more instances).
 * <br/>
 * There is defined no transaction context, the remote call should be load-balanced by EJB client
 * and the first call goes to the first remote server and the second call goes to the second remote server.
 * </p>
 *
 * @return list of strings as return values from the remote beans,
 *         in this case the return values are hostnames and the jboss node names of the remote application server
 * @throws NamingException when remote lookup fails
 */
@TransactionAttribute(value = TransactionAttributeType.NOT_SUPPORTED)
public List<String> remoteOutboundStatelessNoTxBeanCall() throws NamingException {
    log.debugf("Calling with outbound connection without transaction to StatelessBean.successOnCall()");
    RemoteBeanInterface bean = RemoteLookupHelper.lookupRemoteEJBOutbound("StatelessBean", RemoteBeanInterface.class, false);
    List<String> callResponses = new ArrayList<>();
    for (int i = 1; i <= 20; i++) {
        callResponses.add(bean.successOnCall());
    }
    return callResponses;
}
Also used : ArrayList(java.util.ArrayList) RemoteBeanInterface(org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 4 with RemoteBeanInterface

use of org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface in project quickstart by wildfly.

the class RemoteBeanCaller method directLookupStatelessBeanOverHttpCall.

/**
 * This is the same invocation as for {@link #directLookupStatelessBeanOverEjbRemotingCall}.
 * The difference is that there is used the HTTP protocol for EJB calls. Each invocation will be a HTTP request.
 *
 * @return list of strings as return values from the remote beans,
 *         in this case the return values are hostname and the jboss node names of the remote application server
 * @throws NamingException when remote lookup fails
 */
public List<String> directLookupStatelessBeanOverHttpCall() throws NamingException {
    log.debugf("Calling direct lookup with transaction to StatelessBean.successOnCall()");
    String remoteHost = System.getProperty("remote.server.host");
    int remotePort = Integer.getInteger("remote.server.port", 0);
    String remoteUsername = System.getProperty("remote.server.username");
    String remotePassword = System.getProperty("remote.server.password");
    RemoteBeanInterface bean = RemoteLookupHelper.lookupRemoteEJBDirect("StatelessBean", RemoteBeanInterface.class, false, remoteHost, remotePort, remoteUsername, remotePassword, true);
    return Arrays.asList(bean.successOnCall(), bean.successOnCall());
}
Also used : RemoteBeanInterface(org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface)

Example 5 with RemoteBeanInterface

use of org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface in project quickstart by wildfly.

the class RemoteBeanCaller method remoteOutboundStatelessBeanCall.

/**
 * <p>
 * The method calls the remote EJB {@link Stateless} endpoint.
 * </p>
 * <p>
 * To lookup the remote endpoint is used remote outbound connection defined in the <code>standalone.xml</code> configuration file.
 * The deployment links to the configuration by descriptor <code>WEB-INF/jboss-ejb-client.xml</code>.
 * </p>
 *
 * <p>
 * The demonstration shows what happens when two subsequent calls are run within started transaction.<br/>
 * (The default {@link TransactionAttribute} value is {@link TransactionAttributeType#REQUIRED}.)
 * </p>
 * <p>
 * There is no difference with one remote server (started only one instance of <code>server2</code>).
 * It makes a difference if there are two remote servers clustered (<code>server2</code> is run in HA with two instances).
 * <br/>
 * In such case the remote call will reach the same server for both remote ejb invocations.
 * It's because of the transaction affinity which has to be provided by EJB client.
 * </p>
 *
 * @return list of strings as return values from the remote beans,
 *         in this case the return value is a hostname and the jboss node name of the remote application server
 * @throws NamingException when remote lookup fails
 */
public List<String> remoteOutboundStatelessBeanCall() throws NamingException {
    log.debugf("Calling with outbound connection with transaction to StatelessBean.successOnCall()");
    em.persist(new CallerUser("Bilbo", "Baggins"));
    RemoteBeanInterface bean = RemoteLookupHelper.lookupRemoteEJBOutbound("StatelessBean", RemoteBeanInterface.class, false);
    return Arrays.asList(bean.successOnCall(), bean.successOnCall());
}
Also used : CallerUser(org.jboss.as.quickstarts.ejb.entity.CallerUser) RemoteBeanInterface(org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface)

Aggregations

RemoteBeanInterface (org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface)6 TransactionAttribute (javax.ejb.TransactionAttribute)2 CallerUser (org.jboss.as.quickstarts.ejb.entity.CallerUser)2 ArrayList (java.util.ArrayList)1