У меня есть приложение на сервере GF V3.01 и удаленные методы в контейнере EJB. Когда я вызываю удаленные методы из моего приложения для удаленного запуска, требуется много времени для выполнения. Я читал о ServiceLocator, но не могу найти примеры для удаленного приложения Swing. Кто-то, пожалуйста, помогите! дать некоторую идею ускорить вызовы удаленных методов.EJB call from swing
создать этот тест и сделать некоторые комментарии, если это не действует подход
/** Remote interface CountryManagerRemote */
@Remote общедоступный интерфейс CountryManagerRemote расширяет EJBHome {
public String createCountry(Country country);
public String editCountry(Country country);
public List<Country> listAllCountry();
}
/* * Реализация CountryManagerRemote */
@Stateless общественного класса CountryManagerBean реализует CountryManagerRemote {
/** persistance context and other initialization */
/**
* Default constructor.
*/
public CountryCityRegister() {
}
/** implementation of CountryManagerRemote */
public String createCountry(Country country) {
return "massage about operation succesed/failed";
}
public String editCountry(Country country) {
return "massage about operation succesed/failed";
}
public List<Country> listAllCountry(){
return List<Country>
}
/** EJBHome methods without implementation */
@Override
public EJBMetaData getEJBMetaData() throws RemoteException {
// TODO Auto-generated method stub
return null;
}
@Override
public HomeHandle getHomeHandle() throws RemoteException {
// TODO Auto-generated method stub
return null;
}
@Override
public void remove(Handle handle) throws RemoteException, RemoveException {
// TODO Auto-generated method stub
}
@Override
public void remove(Object primaryKey) throws RemoteException, RemoveException {
// TODO Auto-generated method stub
}
}
/** удаленный код качели приложение */ общественного класса ClientApp {
public static void main(String[] args) {
System.setProperty("java.security.auth.login.config", "auth.conf");
System.setProperty("org.omg.CORBA.ORBInitialPort", "***serverport***");
System.setProperty("org.omg.CORBA.ORBInitialHost", "***serverip***");
ProgrammaticLogin programmaticLogin = new ProgrammaticLogin();
try {
// GF programatic login with custom realm
programmaticLogin.login("username", "userpass");
/**Obtain servicelocator instance*/
ServiceLocator service=ServiceLocator.getInstance();
/**FIRST GAIN OF EJB BEAN IT TAKE LONG TIME FOR FIRST LOOKUP*/
CountryManagerRemote manager=(CountryManagerRemote manager)service.getRemoteHome("com.CountryManagerRemote", com.CountryManagerRemote.class);
List<Country> countryList=manager.listAllCountry();
if(countryList!=null){
//SHOW LIST
}
**/**ANOTHER PLACE OF SWING APP*/**
/**SECOND INVOCATION OF BEAN IT ONLY TAKE TIME TO GET EJBHome OBJECT FROM ServiceLocator CACHE*/
CountryManagerRemote manager=(CountryManagerRemote manager)service.getRemoteHome("com.CountryManagerRemote", com.CountryManagerRemote.class);
List<Country> countryList=manager.listAllCountry();
if(countryList!=null){
//SHOW LIST
}
} catch (Exception e1) {
System.err.println("Inform User about exception");
}
}
}
/** ServiceLocator для удаленного ejb */
общественного класса ServiceLocator {
private InitialContext ic;
private Map<String, EJBHome> cache;
private static ServiceLocator me;
static {
try {
me = new ServiceLocator();
} catch (ServiceLocatorException se) {
System.err.println(se);
se.printStackTrace(System.err);
}
}
private ServiceLocator() throws ServiceLocatorException {
try {
ic = new InitialContext();
cache = Collections.synchronizedMap(new HashMap<String, EJBHome>());
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
}
}
static public ServiceLocator getInstance() {
return me;
}
public EJBHome getRemoteHome(String jndiHomeName, Class<?> className) throws ServiceLocatorException {
EJBHome home = null;
try {
if (cache.containsKey(jndiHomeName)) {
home = (EJBHome) cache.get(jndiHomeName);
} else {
Object objref = ic.lookup(jndiHomeName);
Object obj = PortableRemoteObject.narrow(objref, className);
home = (EJBHome) obj;
cache.put(jndiHomeName, home);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return home;
}
}
Сколько звонков вы делаете? мой опыт заключается в том, что для совершения нескольких звонков пользователю не требуется заметного количества времени. Может, у вас есть еще одна проблема? Сколько времени требуется, чтобы сделать один звонок? –
от 2 до 7 секунд. – dimitri
неудобно ждать больше, чем за две секунды до появления кадра – dimitri