ScheduleNode tocombine = sn2sn.get(tmpcombine.node);
ScheduleNode root = sn2sn.get(rootnodes.elementAt(tmpcombine.root).elementAt(tmpcombine.index));
ScheduleEdge se = (ScheduleEdge)tocombine.inedges().next();
- try{
+ try {
if(root.equals(((ScheduleNode)se.getSource()))) {
root.mergeSEdge(se);
if(ScheduleEdge.NEWEDGE == se.getType()) {
*/
public String toString(FlagDescriptor[] flags) {
StringBuffer sb = new StringBuffer(flagstate.size());
- for(int i=0; i < flags.length; i++)
- {
+ for(int i=0; i < flags.length; i++){
if (get(flags[i]))
sb.append(1);
else
private FlagState canonicalizeFlagState(Hashtable sourcenodes, FlagState fs) {
if (sourcenodes.containsKey(fs))
return (FlagState)sourcenodes.get(fs);
- else{
+ else {
sourcenodes.put(fs,fs);
return fs;
}
private TaskNode canonicalizeTaskNode(Hashtable nodes, TaskNode node) {
if (nodes.containsKey(node))
return (TaskNode)nodes.get(node);
- else{
+ else {
nodes.put(node,node);
return (TaskNode)node;
}
int random;
// Do a little bit unrolling of the above algorithm.
int max = bytes.length & ~0x3;
- for (int i = 0; i < max; i += 4)
- {
+ for (int i = 0; i < max; i += 4){
random = next(32);
bytes[i] = (byte) random;
bytes[i + 1] = (byte) (random >> 8);
}
if (max < bytes.length){
random = next(32);
- for (int j = max; j < bytes.length; j++)
- {
+ for (int j = max; j < bytes.length; j++){
bytes[j] = (byte) random;
random >>= 8;
}
"Server : SpinWeb Custom HTTP Server\n" + // server type
"Content-Type: " + contentType + "\n" + // type
"Content-Length: "+ fileLength + "\n\n"; // length
- try{
+ try {
out.write(header.getBytes());
- }
- catch(IOException e){
+ } catch(IOException e) {
e.printStackTrace(); // do nothing!
}
}
buffer = new byte[1024];
- try{
+ try {
while((size = reader.read(buffer,0,buffer.length)) != -1)
out.write(buffer,0,size);
reader.close();
- }
- catch(IOException e){
+ } catch(IOException e) {
e.printStackTrace();
resp.returnCode = 501; // error during transmision
}
OutputStream out,HTTPResponse resp) {
FileInputStream reader = null;
- try{
+ try {
reader = get_reader(fileName, resp);
resp.returnCode = 200;
- }
- catch(IOException e){
+ } catch(IOException e) {
resp.returnCode = 404; // file not found
}
if(resp.returnCode == 200)
HTTPHeader.send_header(out, resp.returnCode, fileName, resp.sentBytes);
- else{
+ else {
HTTPHeader.send_header(out, resp.returnCode, fileName, 0);
return null;
}
public JhttpServer(int port, WebInterface webinterface) {
System.out.println("starting...");
this.webinterface=webinterface;
- try{
+ try {
System.out.println("creating the port");
server = new ServerSocket(port);
- }
- catch (IOException e){
+ } catch (IOException e) {
System.err.println(e);
System.exit(1);
}
public void run() {
// infinite loop
while (true){
- try{
+ try {
startWorker(server.accept());
- }
- catch (Exception e){
+ } catch (Exception e) {
System.err.println(e);
}
}
client.getInputStream()));
out = client.getOutputStream();
- }
- catch(IOException e){
+ } catch(IOException e) {
// I'm not too good at HTTP. Normally, we should put some
// error code here. Anyway, I have assumed that an error
// is equivalent to an unhandled request / method (501)
resp.returnCode = 501; //error
}
- try{
+ try {
out.flush();
if (logging)
LogFile.write_log(client,methodType,fileName,httpVersion,
out.close();
in.close();
client.close();
- }
- catch(IOException e){
+ } catch(IOException e) {
; // do nothing
}
}
private int method(BufferedReader in) {
int ret = -1;
- try{
+ try {
String line;
// read just the first line
if ( str.equals("GET") ){
ret = 0;
methodType = "GET";
- } else if ( str.equals("HEAD") ) {
+ } else if ( str.equals("HEAD") ) {
ret = 1;
methodType = "HEAD";
- } else if ( str.equals("POST") ) {
+ } else if ( str.equals("POST") ) {
ret = 2;
methodType = "POST";
- } else{
+ } else {
System.out.println("501 - unsupported request:" +str);
return -1;
}
- } else{
+ } else {
// System.out.println("Request from browser was empty!");
return -1;
}
break;
}
}
- }
- catch(Exception e){
+ } catch(Exception e) {
System.err.println(e);
return -1;
}
ReturnCode + " " + // 200-500
BytesSent + "\n"; // bytes sent
- try{
+ try {
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(log_file_name, true)));
out.write(Entry,0,Entry.length());
out.flush();
out.close();
- }
- catch (IOException e){
+ } catch (IOException e) {
System.err.println("Gicu " + e);
}
}
private String task(TaskDescriptor td, OutputStream out, HTTPResponse resp) {
- try{
+ try {
PrintWriter pw=new PrintWriter(out);
pw.println("<br><br><h3>Task: "+td.toString()+"</h3><br>");
printTask(td,pw);
}
pw.flush();
- } catch (Exception e) {e.printStackTrace(); System.exit(-1);}
+ } catch (Exception e) {
+ e.printStackTrace(); System.exit(-1);
+ }
return null;
}
private String printTask(TaskDescriptor td, PrintWriter pw) {
- try{
+ try {
for(int i=0; i < td.numParameters(); i++){
pw.println("FlagState Graph: <a href=\"/"+td.getParamType(i)+".html\">"+td.getParamType(i)+"</a><br>");
+td.getParamType(i)+"</a><br>");
}
pw.flush();
- } catch(Exception e) {e.printStackTrace(); System.exit(-1);}
+ } catch(Exception e) {
+ e.printStackTrace(); System.exit(-1);
+ }
return null;
}
for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();){
FlagState root=(FlagState)it_rootnodes.next();
if (root.getLabel().equals((String)cd_nodeid.elementAt(1))){
- try{
+ try {
PrintWriter pw=new PrintWriter(out);
pw.println("<br><br><h3>Allocating tasks for "+root.getTextLabel()+":</h3><br>");
Vector tasks=root.getAllocatingTasks();
printTask(td,pw);
}
- } catch (Exception e) {e.printStackTrace(); System.exit(-1);}
+ } catch (Exception e) {
+ e.printStackTrace(); System.exit(-1);
+ }
break;
}
}
pw.flush();
- } catch (Exception e) {e.printStackTrace(); System.exit(-1);}
+ } catch (Exception e) {
+ e.printStackTrace(); System.exit(-1);
+ }
return null;
}
pw.println(str);
}
pw.flush();
- } catch (Exception e) {e.printStackTrace(); System.exit(-1);}
+ } catch (Exception e) {
+ e.printStackTrace(); System.exit(-1);
+ }
return null;
}
pw.println(str);
pw.flush();
- } catch (Exception e) {e.printStackTrace(); System.exit(-1);}
+ } catch (Exception e) {
+ e.printStackTrace(); System.exit(-1);
+ }
return null;
}
else if (option.equals("-flatirtasks")) {
state.FLATIRGRAPH=true;
state.FLATIRGRAPHTASKS=true;
- } else if (option.equals("-flatirusermethods")) {
+ } else if (option.equals("-flatirusermethods")) {
state.FLATIRGRAPH=true;
state.FLATIRGRAPHUSERMETHODS=true;
- } else if (option.equals("-flatirlibmethods")) {
+ } else if (option.equals("-flatirlibmethods")) {
state.FLATIRGRAPH=true;
state.FLATIRGRAPHLIBMETHODS=true;
} else if (option.equals("-multicore"))
write4(&outBuffer[1], key);
write4(&outBuffer[5], val);
- for (i = 0; i < INSERT_RETRIES; i++)
- {
+ for (i = 0; i < INSERT_RETRIES; i++){
if (sendto(pollsock.fd, outBuffer, 9, 0, (struct sockaddr *)&toAddr,
socklen) < 0){
perror("dhtInsert():sendto()");
int i;
status = 0;
- for (i = 0; i < numKeys; i++)
- {
+ for (i = 0; i < numKeys; i++){
if (dhtInsert(keys[i], vals[i]) != 0)
status = -1;
}
outBuffer[0] = REMOVE_CMD;
write4(&outBuffer[1], key);
- for (i = 0; i < REMOVE_RETRIES; i++)
- {
+ for (i = 0; i < REMOVE_RETRIES; i++){
if (sendto(pollsock.fd, outBuffer, 5, 0, (struct sockaddr *)&toAddr,
socklen) < 0){
perror("dhtRemove():sendto()");
int i;
status = 0;
- for (i = 0; i < numKeys; i++)
- {
+ for (i = 0; i < numKeys; i++){
if (dhtRemove(keys[i]) != 0)
status = -1;
}
outBuffer[0] = SEARCH_CMD;
write4(&outBuffer[1], key);
- for (i = 0; i < SEARCH_RETRIES; i++)
- {
+ for (i = 0; i < SEARCH_RETRIES; i++){
if (sendto(pollsock.fd, outBuffer, 5, 0, (struct sockaddr *)&toAddr,
socklen) < 0){
perror("dhtSearch():sendto()");
int dhtSearchMult(unsigned int numKeys, unsigned int *keys, unsigned int *vals) {
int i;
int status = 0;
- for (i = 0; i < numKeys; i++)
- {
+ for (i = 0; i < numKeys; i++){
if (dhtSearch(keys[i], &vals[i]) != 0)
status = -1;
}
int udpSendAll(unsigned char *msg, unsigned int size) {
int i;
int status = 0;
- for (i = 0; i < numHosts; i++)
- {
+ for (i = 0; i < numHosts; i++){
if ((hostReplied[i] == 0) && (hostArray[i].ipAddr != myHostData.ipAddr)){
if (udpSend(msg, size, hostArray[i].ipAddr) != 0)
status = -1;
if (i == -1)
return -1;
- for (j = 0; j < numBlocks; j++)
- {
+ for (j = 0; j < numBlocks; j++){
if (blockOwnerArray[j] == i)
blockOwnerArray[j] = 0; //TODO: is this what I want to have happen?
else if (blockOwnerArray[j] > i)
blockOwnerArray[j]--;
}
- for (; i < numHosts - 1; i++)
- {
+ for (; i < numHosts - 1; i++){
hostArray[i] = hostArray[i+1];
hostReplied[i] = hostReplied[i+1];
}
void removeUnresponsiveHosts() {
int i;
- for (i = 0; i < numHosts; i++)
- {
+ for (i = 0; i < numHosts; i++){
if (!hostReplied[i] && hostArray[i].ipAddr != myHostData.ipAddr)
removeHost(hostArray[i].ipAddr);
}
int i;
int j;
- for (i = 0; i < numHosts; i++)
- {
+ for (i = 0; i < numHosts; i++){
if (hostArray[i].ipAddr == newHost.ipAddr){
hostArray[i] = newHost;
hostReplied[i] = 0;
return 0;
- } else if (hostArray[i].ipAddr > newHost.ipAddr) {
+ } else if (hostArray[i].ipAddr > newHost.ipAddr) {
if (numHosts == hostArraySize){
newHostArray = calloc(2 * hostArraySize, sizeof(struct hostData));
newHostReplied = calloc(2 * hostArraySize, sizeof(unsigned char));
hostArraySize = 2 * hostArraySize;
} else
{
- for (j = numHosts; j > i; j--)
- {
+ for (j = numHosts; j > i; j--){
hostArray[j] = hostArray[j-1];
hostReplied[j] = hostReplied[j-1];
}
hostArray[i] = newHost;
hostReplied[i] = 0;
}
- for(j = 0; j < numBlocks; j++)
- {
+ for(j = 0; j < numBlocks; j++){
if (blockOwnerArray[j] >= i)
blockOwnerArray[j]++;
}
struct in_addr tmpAddr;
fprintf(logfile, "numHosts = %d\n", numHosts);
- for (i = 0; i < numHosts; i++)
- {
+ for (i = 0; i < numHosts; i++){
tmpAddr.s_addr = htonl(hostArray[i].ipAddr);
fprintf(logfile, "%d) %s, %d\n", i, inet_ntoa(tmpAddr),
hostArray[i].maxKeyCapacity);
oldState = state;
if (pollret < 0){
perror("udpListen():poll()");
- } else if (pollret > 0) {
+ } else if (pollret > 0) {
bytesRcvd = recvfrom(udpPollSock.fd, inBuffer, MAX_MSG_SIZE, 0,
(struct sockaddr *)&peerAddr, &socklen);
if (bytesRcvd < 1){
dhtLog("udpListen(): ERROR: bytesRcvd = %d\n", bytesRcvd);
- } else if (inBuffer[0] >= NUM_MSG_TYPES) {
+ } else if (inBuffer[0] >= NUM_MSG_TYPES) {
dhtLog("udpListen(): ERROR: unknown msg type = %d\n", inBuffer[0]);
- } else if (!msgSizeOk(inBuffer, bytesRcvd)) {
+ } else if (!msgSizeOk(inBuffer, bytesRcvd)) {
dhtLog("udpListen(): ERROR: msg size not ok: type = %s\n, size = %d\n",
msg_types[inBuffer[0]], bytesRcvd);
- } else if (state == EXIT2_STATE) {
+ } else if (state == EXIT2_STATE) {
//do nothing
- } else if (state == INIT1_STATE) { //after initialization with seed, do not proceed until seed replies
+ } else if (state == INIT1_STATE) { //after initialization with seed, do not proceed until seed replies
dhtLog("udpListen(): received %s from %s, %d bytes\n",
msg_types[inBuffer[0]], inet_ntoa(peerAddr.sin_addr), bytesRcvd);
for (i = 0; i < bytesRcvd; i++)
outBuffer[0] = JOIN_RES;
outBuffer[1] = 0; //status, success
udpSend(outBuffer, 2, peerIp);
- } else if (state == LEAD_REBUILD1_STATE) {
+ } else if (state == LEAD_REBUILD1_STATE) {
//note: I don't need to addHost().
checkReplied(peerIp);
outBuffer[0] = JOIN_RES;
case JOIN_RES:
if (state == REBUILD1_STATE){
setState(REBUILD2_STATE);
- } else if (state == INIT2_STATE) {
+ } else if (state == INIT2_STATE) {
setState(NORMAL_STATE);
}
break;
keys = calloc(*numKeys, sizeof(unsigned int));
keyindex = 0;
- for (i = 0; i < mlookup.size; i++)
- {
+ for (i = 0; i < mlookup.size; i++){
if (mlookup.table[i].key != 0){
curr = &mlookup.table[i];
while (curr != NULL){
tmp->numcreated++;
GETSIZE(tmpsize, headeraddr);
tmp->sum_bytes += sizeof(objheader_t) + tmpsize;
- } else if (STATUS(headeraddr) & DIRTY) {
+ } else if (STATUS(headeraddr) & DIRTY) {
tmp->oidmod[tmp->nummod] = OID(headeraddr);
tmp->nummod++;
GETSIZE(tmpsize, headeraddr);
}
if (toremove->lnext!=NULL) {
toremove->lnext->lprev=toremove->lprev;
- } else{
+ } else {
thisvar->listtail=toremove->lprev;
}
RUNFREE(toremove);
}*/
/* Actually call task */
#ifdef PRECISE_GC
- ((int *)taskpointerarray)[0]=currtpd->numParameters;
+ ((int *)taskpointerarray)[0]=currtpd->numParameters;
taskpointerarray[1]=NULL;
#endif
execute:
backtrackinit:
if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed))){
toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
- } else if (j>0) {
+ } else if (j>0) {
/* Need to backtrack */
toiReset(¶meter->iterators[j]);
j--;
backtrackinc:
if(toiHasNext(¶meter->iterators[j], taskpointerarray OPTARG(failed))){
toiNext(¶meter->iterators[j], taskpointerarray OPTARG(failed));
- } else if (j>0) {
+ } else if (j>0) {
/* Need to backtrack */
toiReset(¶meter->iterators[j]);
j--;
}
/* Actually call task */
#ifdef PRECISE_GC
- ((int *)taskpointerarray)[0]=currtpd->numParameters;
+ ((int *)taskpointerarray)[0]=currtpd->numParameters;
taskpointerarray[1]=NULL;
#endif
#ifdef OPTIONAL
sp_func_call_paren = Remove
sp_fparen_brace = Add
sp_sparen_brace = Add
+sp_paren_brace = Add
sp_else_brace = Add
sp_brace_else = Add
sp_catch_brace = Add