Skip to content

Commit

Permalink
Added Job Support. Better Disconnection. Updated JARs
Browse files Browse the repository at this point in the history
  • Loading branch information
dexter1691 committed Mar 15, 2014
1 parent fcc067a commit 60ff515
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 24 deletions.
10 changes: 3 additions & 7 deletions cloudcv.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@

function obj = disconnect(obj)
if(strcmp(class(obj.socket_obj),'SocketConnection'))
javaMethod('unsubscribe',obj.socket_obj);
javaMethod('socket_disconnect',obj.socket_obj);
disp('Disconnecting Redis Server for Socket Connection');
end
if(strcmp(class(obj.upload_obj),'UploadData'))
javaMethod('disconnect',obj.upload_obj);
disp('Disconnecting Redis Server for Post Request');
end
end


Expand All @@ -68,10 +64,10 @@
else
disp('Socket Connection is already established');
javaMethod('updateParameters',obj.socket_obj, obj.params.executable_name, obj.params.output_path);
javaMethod('startRedis', obj.socket_obj);

javaMethod('socketIOConnection', obj.socket_obj);
end
end

end
end

Expand Down
5 changes: 5 additions & 0 deletions jcloudcv/bin/.directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Dolphin]
HeaderColumnWidths=772,64,123
Timestamp=2014,3,15,1,47,34
Version=3
ViewMode=1
Binary file modified jcloudcv/bin/jcloudcv.jar
Binary file not shown.
25 changes: 25 additions & 0 deletions jcloudcv/src/main/java/Job.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
/**
* Created by dexter on 3/15/14.
*/
public class Job
{
public static String imagepath = new String();
public static String resultpath = new String();
public static String output = new String();
public static String executable = new String();
public static String jobid = new String();
public static List<String> files = new Vector<String>();

public static void addFiles(String path)
{
files.add(path);
}

public static String getExecutable(){
return executable;
}

}
8 changes: 5 additions & 3 deletions jcloudcv/src/main/java/SocketConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ else if(key.equals("data"))
{
String str=jobj.getString("data");
System.out.println("Data:" + str);
Job.output = str;
this.redis.publish("intercomm2","{unsubscribe:\"\"}");
}
else if(key.equals("picture"))
{
String str=jobj.getString("picture");
str= "{picture: \"" + str + "\"}";
this.redis.publish("intercomm2", jobj.toString());
}
else if(key.equals("mat"))
Expand Down Expand Up @@ -160,7 +160,8 @@ public void onMessage(String channel, String message)

if(message.startsWith("unsubscribe"))
{
if(_subscriber.isConnected()){
if(_subscriber.isConnected())
{
this.redis_unsubcribe();
System.out.println("Redis Subscriber for Sockets Disconnected");
}
Expand Down Expand Up @@ -202,7 +203,7 @@ public SocketConnection(String exec_name, String output_path)
this._output_path = output_path;

}

public void socketIOConnection() throws Exception
{
SocketIO.setDefaultSSLSocketFactory(SSLContext.getDefault());
Expand All @@ -216,6 +217,7 @@ public void socketIOConnection() throws Exception
{
try
{
socket = new SocketIO("http://godel.ece.vt.edu:8000/");
socket.connect(new SocketCallback(socket,this._exec_name));

} catch (Exception e) {
Expand Down
19 changes: 12 additions & 7 deletions jcloudcv/src/main/java/Sockets_CCV.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ public Sockets_CCV()

public static void main(String[] args) throws IOException
{
ConfigParser cp = new ConfigParser("/home/dexter/workspace/mcloudcv/config.json");

System.out.println(Job.files.size());
System.out.println(Job.files.toString());

ConfigParser cp = new ConfigParser("/home/dexter/workspace/mcloudcv/config.json");
cp.readConfigFile();
int val = cp.parseArguments("","","");
cp.getParams();
Expand All @@ -31,14 +35,15 @@ public static void main(String[] args) throws IOException
SocketConnection sock = new SocketConnection(cp.executable_name, cp.output_path);
sock.socketIOConnection();

Thread t = new Thread(udobj);
t.start();
t.join();

//Thread t = new Thread(udobj);
//t.start();
//t.join();
Thread.sleep(3000);
sock.socket_disconnect();

/* TEST CODE TO CHECK IF RESTART CODE WORKS PROPERLY*/
// sock.updateParameters(cp.executable_name, cp.output_path);
// sock.socketIOConnection();
sock.updateParameters(cp.executable_name, cp.output_path);
sock.socketIOConnection();
// udobj = new UploadData(cp);
// t = new Thread(udobj);
// t.start();
Expand Down
27 changes: 20 additions & 7 deletions jcloudcv/src/main/java/UploadData.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ public void onMessage(String channel, String message) {
url = jobj.getString("picture");
String jobid = new String();
jobid = jobj.getString("jobid");
Job.jobid = jobid;

File theDir = new File(this._output_path, jobid);
Job.resultpath = theDir.getPath();
Job.executable = this._executable_name;
if(!theDir.exists())
{
theDir.mkdir();
}
String fileName = url.substring( url.lastIndexOf('/')+1, url.length());
File theFile = new File(theDir, fileName);
this.getImageAndSave(url,theFile.getPath());

Job.addFiles(theFile.getPath());
}

if(key.equals("mat"))
Expand All @@ -136,7 +139,10 @@ public void onMessage(String channel, String message) {
public UploadData(ConfigParser parser)
{
_source_path = parser.source_path;
_output_path = parser.output_path;

Job.imagepath = _source_path;

_output_path = parser.output_path;
_executable_name = parser.executable_name;
_params = parser.params.toString();

Expand Down Expand Up @@ -273,7 +279,7 @@ public boolean accept(File file) {

}

public String CloudCVPostRequest() throws UnsupportedEncodingException
public String CloudCVPostRequest() throws UnsupportedEncodingException, InterruptedException
{

String token = getToken();
Expand All @@ -289,21 +295,28 @@ public String CloudCVPostRequest() throws UnsupportedEncodingException
reqentity.addPart("token", new StringBody(token));
reqentity.addPart("executable",new StringBody(this._executable_name));
reqentity.addPart("exec_params", new StringBody(this._params));

int i =0;
while(_socketid.equals(""))
{
try
{
System.out.println("Waiting for socket connection ");
Thread.sleep(3000);
if(i<3){
Thread.sleep(3000);
i++;
}
else
{
throw new InterruptedException("Maximum retry over. Exit.");
}
} catch (InterruptedException e)
{
e.printStackTrace();
throw e;
}
}
reqentity.addPart("socketid", new StringBody(this._socketid));

for(int i=0;i<imagecount;i++)
for(i=0;i<imagecount;i++)
{
FileBody fileBody = new FileBody(imagelist[i], "application/octet-stream");

Expand Down
1 change: 1 addition & 0 deletions setup.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
import ConfigParser.*
import SocketConnection.*
import Sockets_CCV.*
import Job.*

0 comments on commit 60ff515

Please sign in to comment.