Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String args[]){
- int port = 7000;
- numeroDeServersTCP = 0;
- boolean portousado = true;
- RmiServer h = null;
- RmiInterface a = null;
- String url = "jdbc:mysql://localhost:5000/ibei";
- String user = "root";
- String password = "alexandre";
- System.setProperty("java.security.policy","policy");
- /////rmiwork
- if(conectDatabase(url,user,password)){
- System.out.println("Conected to DataBase");
- }
- new Thread() {
- public void run() {
- while(true){
- try {
- PreparedStatement pst = null;
- ResultSet rs = null;
- pst = con.prepareStatement("SELECT idauctions, deadline from auctions");
- rs = pst.executeQuery();
- while(rs.next()){
- SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:mm");
- Date t;
- t = (Date) ft.parse(rs.getString(2));
- if(t.before(new Date())){
- pst = con.prepareStatement("UPDATE auctions set active = false where auction_id="+rs.getString(1)+";");
- rs = pst.executeQuery();
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ParseException e) {
- e.printStackTrace();
- }
- try {
- Thread.sleep(60000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }.start();
- Registry registry = null;
- try {
- registry = LocateRegistry.getRegistry("localhost",7000);
- a = (RmiInterface)registry.lookup( "iBeiServer" );
- System.out.println("-------------------BackupRMISERVER----------------------");
- while (true) {
- if (a.getViva().equals("pong")) {
- System.out.println(" O Storage esta ativo \n");
- currentThread().sleep(5000);
- }
- }
- } catch (RemoteException e) {
- System.out.println("deixei de ter conecção com o servidor original");
- try {
- h = new RmiServer();
- Naming.rebind("rmi://localhost:7000/iBeiServer", h);
- } catch (RemoteException e1) {
- // e1.printStackTrace();
- } catch (MalformedURLException e1) {
- //e1.printStackTrace();
- }
- System.out.println("passei a ser o servidor original\n");
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (NotBoundException e) {
- e.printStackTrace();
- }
- try {
- a = (RmiInterface)registry.lookup( "iBeiServer" );
- }catch (RemoteException e) {
- //e.printStackTrace();
- System.out.println("ainda nao ha ninguem com o rmiregistry ligado\n");
- try {
- LocateRegistry.createRegistry(7000);
- h = new RmiServer();
- Naming.rebind("rmi://localhost:7000/iBeiServer", h);
- System.out.println("----------------------RMIServer is ready. running at port : " + port);
- } catch (RemoteException e1) {
- e1.printStackTrace();
- } catch (MalformedURLException e1) {
- System.out.println("ola mano\n");
- e1.printStackTrace();
- }
- }
- catch (NotBoundException e) {
- System.out.println("ainda ninguem fez bind");
- //e.printStackTrace();
- }
- System.out.println("prontinho a funcionar\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement