Search in sources :

Example 1 with CallerUser

use of org.jboss.as.quickstarts.ejb.entity.CallerUser 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 2 with CallerUser

use of org.jboss.as.quickstarts.ejb.entity.CallerUser in project quickstart by wildfly.

the class UsersManagement method printUsers.

public String printUsers() {
    StringBuffer sb = new StringBuffer();
    sb.append(String.format(tableFormatStringForPrint, "ID", "First Name", "Last Name"));
    sb.append(String.format(tableFormatStringForPrint, "---", "---", "---"));
    for (CallerUser user : getUsers()) {
        sb.append(String.format(tableFormatStringForPrint, user.getId(), user.getFirstName(), user.getLastName()));
    }
    return sb.toString();
}
Also used : CallerUser(org.jboss.as.quickstarts.ejb.entity.CallerUser)

Example 3 with CallerUser

use of org.jboss.as.quickstarts.ejb.entity.CallerUser 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

CallerUser (org.jboss.as.quickstarts.ejb.entity.CallerUser)3 RemoteBeanInterface (org.jboss.as.quickstarts.ejb.server.RemoteBeanInterface)2