[{{mminutes}}:{{sseconds}}] X
Пользователь приглашает вас присоединиться к открытой игре игре с друзьями .
jee ejb book fragment
(0)       Используют 18 человек

Комментарии

Ни одного комментария.
Написать тут
Описание:
Короткие отрывки из учебника Enterprise Java Beans 3.1 Фразы на английском, цифры и прочие символы, характерные для java-программ.
Автор:
engineer80
Создан:
12 февраля 2015 в 15:00 (текущая версия от 12 февраля 2015 в 15:21)
Публичный:
Да
Тип словаря:
Тексты
Цельные тексты, разделяемые пустой строкой (единственный текст на словарь также допускается).
Содержание:
1 Here we've declared a JNDI naming Context for the lookups, and the names of the target JNDI Addresses under which we'll find the appropriate proxy reference. Our tests will check that the EJB 3.1 Business View works as expected, but before the test runs, a lifecycle method will obtain the reference and set the proxy reference accordingly:
2 @BeforeClass
public static void obtainProxyReferences() throws Throwable
{
namingContext = new InitialContext();
calc = (SimpleCalculatorBean)
namingContext.lookup(JNDI_NAME_CALC);
}
3 First we create the naming Context, using a standard jndi.properties file that we assume to be present on the classpath. The JNDI properties to be used are vendor-specific, so by pulling these out into a separate file, our test remains portable across EJB implementations.
SessionContext allows you to obtain information such as the current user that is invoking on the EJB, or to look up entries within the EJB's Enterprise Naming Context (ENC). Let's look at the javax.ejb.SessionContext interface:
4 javax.ejb.SessionContext extends javax.ejb.EJBContext {
EJBLocalObject getEJBLocalObject( ) throws IllegalStateException
EJBObject getEJBObject( ) throws IllegalStateException;
MessageContext getMessageContext( ) throws IllegalStateException;
<T> getBusinessObject(Class<T> businessInterface)
throws IllegalStateException;
Class getInvokedBusinessInterface( );
}
5 The SessionContext.getBusinessObject() method returns a reference to the current EJB that can be invoked by other clients. This reference is the EJB equivalent to Java's this pointer, but it returns a proper EJB proxy. The businessInterface parameter must be one of the EJB's BusinessRemote or BusinessLocal interfaces so that the container knows whether to create a remote or local reference to the current EJB. The getBusinessObject() method allows the bean instance to get its own EJB object reference, which it can then pass to other beans. Here is an example:
6 @Stateless
public class A_Bean implements A_BusinessRemote {
@Resource private SessionContext context;
public void someMethod( ) {
B_BeanBusinessRemote b = ...
A_BeanBusinessRemote mySelf = getBusinessObject(A_BeanRemote.class);
b.aMethod( mySelf );
} ... }
7 The callback method can be of any name, but it must return void, have no parameters, and throw no checked exceptions. The bean class may define only one @PostConstruct method (but it is not required to do so). Alternatively, you can declare your @PostConstruct method in the EJB's XML deployment descriptor:
8 log.info("Mock passivation");
final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
final ObjectOutput objectOut = new ObjectOutputStream(outStream);
objectOut.writeObject(client);
objectOut.close();
9 Mocks the passivation - activation process by manually invoking upon the {@link PrePassivate} and {@link PostActivate} lifecycle callbacks. The client should function properly after these calls are made, reconnecting as expected, and resuming into the correct present working directory
10 public String businessMethod( ) {
try{
Connection connect = factory.createConnection( );
Session session = connect.createSession(true,0);
MessageConsumer receiver = session.createConsumer(queue);
TextMessage textMsg = (TextMessage)receiver.receive( );
connect.close( );
return textMsg.getText( );
} catch(Exception e) {
throws new EJBException(e);
}
}

Связаться
Выделить
Выделите фрагменты страницы, относящиеся к вашему сообщению
Скрыть сведения
Скрыть всю личную информацию
Отмена