123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- package com.rdlze.radializebase.utils;
-
- import java.rmi.Remote;
- import java.rmi.RemoteException;
- import java.rmi.registry.LocateRegistry;
- import java.rmi.registry.Registry;
- import java.rmi.server.UnicastRemoteObject;
- import java.sql.Timestamp;
-
- import com.idealizeframework.irf.base.exceptions.IdealizeUnavailableResourceException;
-
- public class Utils {
-
- public static Timestamp getNowDate() {
- return new Timestamp(System.currentTimeMillis());
- }
-
-
-
- public static Remote registerRemoteObject(Remote remoteObject,
- String nameObject, int port) {
-
- try {
- try {
- LocateRegistry.createRegistry(port);
-
- } catch (Exception e) {
- System.out.println("A porta do RMI ja esta sendo utilizada?!");
- }
- Remote stub;
- Registry registry = LocateRegistry.getRegistry(port);
-
- stub = UnicastRemoteObject.exportObject(remoteObject, port);
- System.out.println("Name Obj " + nameObject);
- registry.rebind(nameObject, stub);
- System.out.println("REGISTROU OBJETO " + nameObject
- + " REMOTAMENTE.");
-
- return stub;
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- return remoteObject;
- }
-
-
-
- public static Remote registerRemoteObjectUseRandom(Remote remoteObject,
- String nameObject, int port) {
-
- try {
- try {
- LocateRegistry.createRegistry(port);
-
- } catch (Exception e) {
- System.out.println("A porta do RMI ja esta sendo utilizada?!");
- }
- Remote stub;
- Registry registry = LocateRegistry.getRegistry(port);
-
- stub = UnicastRemoteObject.exportObject(remoteObject, 0);
- System.out.println("Name Obj " + nameObject);
- registry.rebind(nameObject, stub);
- System.out.println("REGISTROU OBJETO " + nameObject
- + " REMOTAMENTE.");
-
- return stub;
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- return remoteObject;
- }
-
- public static Remote getRemoteObject(String ipObject, String nameObject,
- int port) {
-
- Remote remote = null;
- try {
- Registry registry = LocateRegistry.getRegistry(ipObject, port);
- remote = registry.lookup(nameObject);
- if (remote == null) {
- System.out.println("NÃO PEGOU O OBJETO " + nameObject
- + " REMOTAMENTE. O OBJETO ESTÁ NULO. IP: " + ipObject
- + " NAME: " + nameObject + " PORTA: " + port);
-
- } else {
- System.out.println("PEGOU O OBJETO " + nameObject
- + " REMOTAMENTE.");
- }
- } catch (Exception e) {
- e.printStackTrace();
- System.err
- .println("Could not possible get remote object: nameObject: "
- + nameObject + " IP Object: " + ipObject);
- remote = null;
- }
- return remote;
- }
-
-
-
- public static Remote registerRemoteObject(Remote remoteObject,
- String nameObject, String host, int port) {
-
- try {
- try {
- LocateRegistry.createRegistry(port);
-
- } catch (Exception e) {
- System.out.println("A porta do RMI ja esta sendo utilizada?!");
- }
- Remote stub;
- Registry registry = LocateRegistry.getRegistry(host, port);
-
- stub = UnicastRemoteObject.exportObject(remoteObject, port);
- System.out.println("Name Obj " + nameObject);
- registry.rebind(nameObject, stub);
- System.out.println("REGISTROU OBJETO " + nameObject
- + " REMOTAMENTE.");
-
- return stub;
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- return remoteObject;
- }
-
- public String escapeUnicode(String name) {
- name = name.replaceAll("'", "''");
- name = name.replaceAll("\\", "'\\");
- return name;
- }
- }
|