Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [stellation-res] Timing: The Problem

On Fri, Sep 13, 2002 at 10:04:20AM -0400, Dave Shields wrote:
> 
> I will post a followup note with the diff output showing my recent
> changes. 

diff workspace/Checkin.java /home/shields/svc/org.eclipse.stellation.core/src/org/eclipse/stellation/workspace/Checkin.java
14a15
> import java.util.Date;
50a52,53
>         long checkTime = new Long(new Date().getTime()).longValue();
>         getWorkspace().setAttribute("checkout", new Long(checkTime).toString());
252a256
>             getWorkspace().getFiles().waitCheck(checkTime);
diff workspace/Checkout.java /home/shields/svc/org.eclipse.stellation.core/src/org/eclipse/stellation/workspace/Checkout.java
57a58,59
>         long checkTime = new Long(new Date().getTime()).longValue();
>         getWorkspace().setAttribute("checkout", new Long(checkTime).toString());
139,140d140
<         String checkoutTime = new Long(new Date().getTime()).toString();
<         getWorkspace().setAttribute("checkout", checkoutTime);
213,224c213
<         // Timer on file update time is only one second so need to
<         // wait at least that long so that any new files created will
<         // show different time
<         try {
<             synchronized (this) {
<                 wait(1050L);
<             }
<         }
<         catch (InterruptedException e) {
<             ; // Oh well, at least we tried to wait...
<         }
< 
---
>         getWorkspace().getFiles().waitCheck(checkTime);
diff workspace/Configure.java /home/shields/svc/org.eclipse.stellation.core/src/org/eclipse/stellation/workspace/Configure.java
13a14
> import java.io.FileWriter;
15a17,18
> import java.util.Date;
> 
53,60c56,64
<                 .add("database", "rest")
<                 .add("user", "rest")
<                 .add("password", "rest")
<                 .add("default")
<                 .add("empty")
<                 .add("option", "rest")
<                 .add("type", "rest")
<                 .add("within");
---
>             .add("client")
>             .add("database", "rest")
>             .add("user", "rest")
>             .add("password", "rest")
>             .add("default")
>             .add("empty")
>             .add("option", "rest")
>             .add("type", "rest")
>             .add("within");
69c73,76
<             if (name.equals("database")) {
---
>             if (name.equals("client")) {
>                 client();
>             }
>             else if (name.equals("database")) {
105a113,174
>     }
> 
>            
>     class ConfigureClient {
>         public  long now() {
>             return new Long(new Date().getTime()).longValue();
>         }
>         public   long seconds(long time) {
>             return time - ( time % 1000L);
>         }
>         
>         public  long elapsed(long now, long start) {
>             return now - start;
>         }
> 
>         public void configure () throws IOException {
>             int passes = 25;
>             long totalDifference = 0L;
>             long start = seconds(now()); // Start time
>             File file =  File.createTempFile("svc-config","foo");
>             for (int i = 0; i < passes; i++) {
>                 if (file.exists()) file.delete();
>                 FileWriter fileWriter = new FileWriter(file);
>                 fileWriter.write(new char[] {'b', 'a', 'r', '\n' });
>                 fileWriter.flush();
>                 fileWriter.close();
>                 long fileTime = file.lastModified();
>                 long now = now();
>                 if (fileTime > now) totalDifference += (fileTime - now);
>                 else if (fileTime < now) totalDifference += (now - fileTime);
>                 System.out.println("difference " + totalDifference);
>                 try {
>                     synchronized (this) {
>                         super.wait(100L);
>                     }
>                 }
>                 catch (InterruptedException e) {
>                     ; // Oh well, at least we tried to wait...
>                 }
>                 if (file.exists()) file.delete();
>             }
>             if (totalDifference == 0L) {
>                 System.out.println("No actoin needed.");
>                 return;
>             }
> 
>             // Set configuration value at twice the average difference .
>             long  waitTime = (2L * totalDifference)  / passes;
>             Configuration configuration = getCurrentConfiguration();
>             StringMap configurationOptions = configuration.getOptions();
>             configurationOptions.put("svc-check-wait", new Long(waitTime).toString());
>             outputConfiguration(configuration);
>         }
> 
>     }
>     /**
>      * Configures client. Currently this involves determining if the obscure
>      * svc-check-wait options should be used.
>      */
>     public void client() throws IOException {
>         // Assume have write-access to current directory
>         new ConfigureClient().configure();
diff workspace/Files.java /home/shields/svc/org.eclipse.stellation.core/src/org/eclipse/stellation/workspace/Files.java
95a96,97
>         String checkWaitOption = _workspace.getContext().getOptions().get("svc-check-wait","");
>         if (checkWaitOption.startsWith("-")) _trustClock = false;
1204a1207,1214
>      * See if clock can be trusted.
>      *
>      */
>     public boolean trustClock() {
>         return _trustClock;
>     }
> 
>     /**
1265a1276,1324
> 
>     /**
>      * Waits until system clock has moved on to the next second after a 
>      * specified time.
>      *
>      * Even though times are measured in milliseconds, the resolution
>      * of the times reported by File.lastModified() has been observed
>      * to be at most one second. As a result, the command sequence:
>      *<pre>
>      * echo "old" > file
>      * svc checkin
>      * echo "new" > file
>      * svc test modified
>      *</pre>
>      * may return spurious results if both svc commands are executed
>      * in the same second, as the file time will appear to not have
>      * changed.  This method waits until the system clock has moved
>      * into the 'next' second in order to avoid this problem.
>      *
>      *
>      * @param checkTime the starting time for the wait. This time is
>      * noted by the checkout and checkin commands as they start
>      * execution, as no workspace file can have a modification time
>      * later than this time
>      */
>     public void waitCheck(long checkTime) {
>         String checkWaitOption = getWorkspace().getContext().getOptions().get("svc-check-wait","");
>         if (checkWaitOption.equals("") 
>             || checkWaitOption.equals("0")
>             || checkWaitOption.startsWith("-"))
>             return;
>         checkTime = checkTime - (checkTime% 1000L); // round down to nearest second
>         long waitTime = new Long(checkWaitOption).longValue();
>                                                     // 
>         long currentTime = new Long(new Date().getTime()).longValue();
>         while (currentTime > checkTime && currentTime < (checkTime + waitTime)) {
>             System.out.println("check-wait waiting");
>             try {
>                 synchronized (this) {
>                     wait(100L); // Wait 100 milliseconds.
>                 }
>             }
>             catch (InterruptedException e) {
>                 ;
>             }
>             currentTime = new Long(new Date().getTime()).longValue();
>         }
>     }
> 
1282a1342,1343
> 
>     protected boolean _trustClock = true;  // Assume system clock and file modification time accurate
diff workspace/Project.java /home/shields/svc/org.eclipse.stellation.core/src/org/eclipse/stellation/workspace/Project.java
643a644
>         boolean trustClock = _workspace.getFiles().trustClock();
664,667c665,675
<             long entryTime = new Long(eAttributes.get("time")).longValue();
<             long lastModified = file.lastModified();
<             if (entryTime != lastModified) { 
<                 artifact.setTime(lastModified);
---
>             if (trustClock) {
>                 long entryTime = new Long(eAttributes.get("time")).longValue();
>                 long lastModified = file.lastModified();
>                 if (entryTime != lastModified) {
>                     artifact.setTime(lastModified);
>                     artifact.computeSignature();
>                 }
>             }
>             else {
>                 // No need to set modification time if not trusting clock,
>                 // but must compute signature
diff workspace/Svc.java /home/shields/svc/org.eclipse.stellation.core/src/org/eclipse/stellation/workspace/Svc.java
390a391
>             .add("svc-check-wait", "property", true)
-- 
Dave Shields, IBM Research, shields@xxxxxxxxxxxxxx. 


Back to the top