@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object res = null; { long t0 = System.nanoTime(); try { res = method.invoke(resource, args); } catch (InvocationTargetException ex) { throw ex.getTargetException(); } catch (Exception ex) { throw ex; } finally { long t1 = System.nanoTime(); long t = t1 - t0; log(method, args, t); } } return res; }
/** Stops execution time measurement. */ public void stop() { add(System.nanoTime() - startClock); }
/** Starts execution time measurement. */ public void start() { startClock = System.nanoTime(); }
public static void main(String args[]) throws InterruptedException, IOException { int i, j; String serverInetAddress = "localhost"; String server1AddressString = "10.10.1.1"; InetAddress server1Address = InetAddress.getByName(server1AddressString); String server2AddressString = "10.10.2.2"; InetAddress server2Address = InetAddress.getByName(server2AddressString); String server3AddressString = "10.10.3.2"; InetAddress server3Address = InetAddress.getByName(server3AddressString); String server4AddressString = "localhost"; InetAddress server4Address = InetAddress.getByName(server4AddressString); DatagramSocket skt; { skt = new DatagramSocket(PORT_NUMBER_CLIENT); // socket used to listen and write InetAddress host = InetAddress.getByName(serverInetAddress); int serversocket = S1.PORT_NUMBER_SERVER; String msg = "Send file size"; byte[] b = msg.getBytes(); // dummy assignments - not used anywhere int filesize = 1; DatagramPacket reply, request; reply = new DatagramPacket(b, b.length, host, serversocket); request = new DatagramPacket(b, b.length, host, serversocket); for (i = 1; i <= 3; i++) { // defining a packet called request with parameters b(msg in bytes), b.length, host Internet // address and socket number if (i == 1) { host = server1Address; } else if (i == 2) { host = server2Address; } else if (i == 3) { host = server3Address; } request = new DatagramPacket(b, b.length, host, serversocket); // System.out.println("request sent from client to server"); Thread.sleep(S1.PAUSE_DURATION); // for error checks // Sending the packet- for getting the file size skt.send(request); // getting reply from // server........................................................................................ byte[] buffer = new byte [S1.PACKET_SIZE]; // apparently the size of data packet at the receiving side needs // to be bigger than the size of incoming datapacket reply = new DatagramPacket(buffer, buffer.length); // receiving packet from server - contatining filesize skt.receive(reply); // System.out.println("Response Received from server"); // System.out.println("on Client: - filesize= "+new String(reply.getData())); filesize = Integer.parseInt(new String(reply.getData()).trim()); // System.out.println("on Client: - filesize= "+filesize); Thread.sleep(S1.PAUSE_DURATION); } // here the client know the size of the file // Find the number of times it must make iterations - dividing filesize by packet_size // Request that many packets from server String[] buffer_string = new String[BUFFER_SIZE_CLIENT]; float delay[] = new float[filesize / S1.PACKET_SIZE]; System.out.println(filesize); System.out.println(S1.PACKET_SIZE); System.out.println(filesize / S1.PACKET_SIZE); Thread.sleep(2000); byte[] buffer = new byte[S1.PACKET_SIZE]; for (i = 0; i < filesize / S1.PACKET_SIZE; i++) { if (i % 100 != 0) { // System.out.print(" "+i); } else { System.out.println(" " + i); } msg = String.valueOf(i); b = msg.getBytes(); if (i % 3 == 0) { host = server1Address; } else if (i % 3 == 1) { host = server2Address; } else if (i % 3 == 2) { host = server3Address; } request = new DatagramPacket(b, b.length, host, serversocket); skt.send(request); delay[i] = System.nanoTime(); Thread.sleep(10); skt.receive(reply); delay[i] = System.nanoTime() - delay[i]; delay[i] = delay[i] / (1000000); /* if(empty_index<BUFFER_SIZE_CLIENT) { buffer_string[empty_index]=new String(reply.getData()); empty_index++; } else { for(j=0;j<BUFFER_SIZE_CLIENT-1;j++) { buffer_string[j]=buffer_string[j+1]; } buffer_string[BUFFER_SIZE_CLIENT-1]=new String(reply.getData()); }*/ // display_buffer(buffer_string); } Arrays.sort(delay); float delay2[] = new float[filesize / S1.PACKET_SIZE]; for (i = 0; i < delay2.length; i++) { delay2[i] = delay[delay.length - i - 1]; } // delay2 stores the array in descending values float[] Sk = new float[filesize / S1.PACKET_SIZE]; Sk[0] = (float) 0.0; for (i = 1; i < filesize / S1.PACKET_SIZE; i++) { for (j = 1; j <= i; j++) { Sk[i] = Sk[i] + delay2[j]; } Sk[i] = Sk[i] / (10 * i); } make_output(Sk); System.out.format( "Sk at 2=%f\n,10=%f\n,20=%f\n,100=%f\n and 30000=%f\n ", Sk[1], Sk[9], Sk[19], Sk[99], Sk[29999]); // display_buffer(buffer_string); skt.close(); } }
public void executePlay() { println("play"); isPlaying = true; startTime = System.nanoTime(); }
public void update() { if (isPlaying) { // only plays sound for dialog if (sMan.eventHappened(getPosInSeconds())) { // put sound code here!!! sMan.peekNextEvent().execute(getPosInSeconds()); println(sMan.popEvent()); } // find if previous dialog should still be playing, and if so, play it if (sMan.getPreviousPoppedDialog(getPosInSeconds()) != null) { sMan.getPreviousPoppedDialog(getPosInSeconds()).execute(getPosInSeconds()); // println(sMan.getPreviousPoppedDialog(getPosInSeconds())); } } if (overSlide()) { over = true; } else { over = false; } if (mousePressed && over) { locked = true; } if (!mousePressed) { locked = false; } if (locked) { newspos = constrain(mouseX - sheight / 2, sposMin, sposMax); } if (abs(newspos - spos) > 1 || isPlaying) { // if playback has collided with the end of the timeline, stop playing if (isPlaying) { if (getPosInSeconds() >= totalTime) { executePause(); } } if (isPlaying) { long estimatedTime = System.nanoTime() - startTime; if (estimatedTime / 1000000000 >= 1) { // if one second has passed, make a new start time (reset the second timer) startTime = System.nanoTime(); // println("before spos is " + spos + " time is " + getPosInSeconds()); spos = incrementSposInSeconds(); println( "spos is " + spos + " time is " + getPosInSeconds() + " frame is " + getPosInFrames()); } } else { spos = spos + (newspos - spos) / loose; } } // if the timeline is NOT playing, create the queue for the events to unfold in order if (!isPlaying) { sMan.createQueue(getPosInSeconds()); } // println(getPosInSeconds()); }