Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. public static void main(String args[]){
  2. int port = 7000;
  3. numeroDeServersTCP = 0;
  4.  
  5. boolean portousado = true;
  6. RmiServer h = null;
  7. RmiInterface a = null;
  8. String url = "jdbc:mysql://localhost:5000/ibei";
  9. String user = "root";
  10. String password = "alexandre";
  11.  
  12. System.setProperty("java.security.policy","policy");
  13.  
  14. /////rmiwork
  15. if(conectDatabase(url,user,password)){
  16. System.out.println("Conected to DataBase");
  17. }
  18.  
  19. new Thread() {
  20. public void run() {
  21. while(true){
  22. try {
  23. PreparedStatement pst = null;
  24. ResultSet rs = null;
  25.  
  26. pst = con.prepareStatement("SELECT idauctions, deadline from auctions");
  27. rs = pst.executeQuery();
  28. while(rs.next()){
  29.  
  30. SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:mm");
  31. Date t;
  32. t = (Date) ft.parse(rs.getString(2));
  33.  
  34. if(t.before(new Date())){
  35. pst = con.prepareStatement("UPDATE auctions set active = false where auction_id="+rs.getString(1)+";");
  36. rs = pst.executeQuery();
  37. }
  38. }
  39. } catch (SQLException e) {
  40. e.printStackTrace();
  41. } catch (ParseException e) {
  42. e.printStackTrace();
  43. }
  44.  
  45. try {
  46. Thread.sleep(60000);
  47. } catch (InterruptedException e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. }
  52. }.start();
  53. Registry registry = null;
  54. try {
  55. registry = LocateRegistry.getRegistry("localhost",7000);
  56. a = (RmiInterface)registry.lookup( "iBeiServer" );
  57. System.out.println("-------------------BackupRMISERVER----------------------");
  58. while (true) {
  59. if (a.getViva().equals("pong")) {
  60. System.out.println(" O Storage esta ativo \n");
  61. currentThread().sleep(5000);
  62. }
  63. }
  64. } catch (RemoteException e) {
  65. System.out.println("deixei de ter conecção com o servidor original");
  66. try {
  67. h = new RmiServer();
  68. Naming.rebind("rmi://localhost:7000/iBeiServer", h);
  69. } catch (RemoteException e1) {
  70. // e1.printStackTrace();
  71. } catch (MalformedURLException e1) {
  72. //e1.printStackTrace();
  73. }
  74. System.out.println("passei a ser o servidor original\n");
  75. } catch (InterruptedException e) {
  76. e.printStackTrace();
  77. } catch (NotBoundException e) {
  78. e.printStackTrace();
  79. }
  80. try {
  81. a = (RmiInterface)registry.lookup( "iBeiServer" );
  82. }catch (RemoteException e) {
  83. //e.printStackTrace();
  84. System.out.println("ainda nao ha ninguem com o rmiregistry ligado\n");
  85. try {
  86. LocateRegistry.createRegistry(7000);
  87. h = new RmiServer();
  88. Naming.rebind("rmi://localhost:7000/iBeiServer", h);
  89. System.out.println("----------------------RMIServer is ready. running at port : " + port);
  90. } catch (RemoteException e1) {
  91. e1.printStackTrace();
  92. } catch (MalformedURLException e1) {
  93. System.out.println("ola mano\n");
  94. e1.printStackTrace();
  95. }
  96. }
  97. catch (NotBoundException e) {
  98. System.out.println("ainda ninguem fez bind");
  99. //e.printStackTrace();
  100. }
  101. System.out.println("prontinho a funcionar\n");
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement