ProofClient.java 4.51 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
package network.client;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.*;

import zb2smt.ZB2SMTUtils;

import network.Requisition;


public class ProofClient /*implements Runnable*/ {

ArrayList <Thread> listofTrhead = new ArrayList<Thread>();
ArrayList <String> listofServer = new ArrayList<String>();
//File file = new File(System.getProperty("user.dir")+ "/network/Config");
File file = new File(System.getProperty("user.dir")+ ZB2SMTUtils.fs + ZB2SMTUtils.smtSolversStr + ZB2SMTUtils.fs +"Config");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
String proofobligation;
String result;

public static void main(String[] args) {

ProofClient maintrhead = new ProofClient("(= 1 1)");
try {
System.out.print(maintrhead.proveRemotely());
}
catch (Exception e) {
e.printStackTrace();
}
System.exit(0);

}

public ProofClient(String proofobligation) {

this.proofobligation = proofobligation;

}


public synchronized String proveRemotely() throws Exception {

try {

fis = new FileInputStream(file);

// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);

// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {

// this statement reads the line from the file, create a requisition, send this requisition to remote theorem prover and
// print the answer
// the console.

String[] result = dis.readLine().split("@");
if (result.length > 1) {
Requisition req =new Requisition( new String(result[0]),proofobligation,new String(""));
Thread t = new Conection(result[1],req, this);
//System.out.println("Path e param:"+result[0] +"host"+result[1]+"FIM");
try {
t.start();
}
catch (Exception e) {
e.printStackTrace();
return "Error";
}

listofTrhead.add(t);
}


}



// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


try {

this.wait() ;

} catch (InterruptedException e) {
// TODO Auto-generated catch block

e.printStackTrace();

System.err.println("This program can't wait");

}


//System.out.println("Resultado:"+result);


return result;



}


public synchronized void stopOthers(Object obj){

int size = listofTrhead.size();

for (int count = 0 ; count < size ; count++ )
if(listofTrhead.get(count)!= obj)
listofTrhead.get(count).stop();

this.result = new String (((Conection) obj).req.getResult());


}


class Conection extends Thread{

Socket socket;
ObjectOutputStream objoutstream ;
ObjectInputStream objinstream;
String hostname;
Requisition req;
ProofClient father;



public Conection(String hostname, Requisition req, ProofClient father){
this.hostname = hostname;
this.req = req;
this.father = father;

}

public void run(){

Requisition req_answer=null;

try{
socket = new Socket(hostname, 2525);

this.objinstream = new ObjectInputStream(socket.getInputStream() );
this.objoutstream = new ObjectOutputStream(socket.getOutputStream() );

System.out.println("Sending the proof obligation");

objoutstream.writeObject((Requisition) req);

System.out.println("Waiting answer");

req_answer = (Requisition) objinstream.readObject();

/*System.out.println(req_answer.getProvername());
System.out.println(req_answer.getProofobligation());
System.out.println(req_answer.getResult());*/

req_answer = new Requisition("","",req_answer.getResult() );

req.setResult(req_answer.getResult());

father.result = req_answer.getResult();

synchronized(father) {father.notify(); father.stopOthers(this); }


//System.out.println("Result"+req.getResult() );
}catch (Exception e) {
e.printStackTrace();
synchronized(father) {father.notify();}
System.err.println("Cannot call the remote prover.");
}



}
}




}