mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Wasn't updating mod time in appropriate places. Fixed that. Rewrote Issuer
to be less stupid. Minor fix to the pathetically silly reallybad.jsp. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3276 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -17,89 +17,24 @@
|
||||
|
||||
package org.alfresco.repo.avm;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This is a helper class that knows how to issue identifiers.
|
||||
* @author britt
|
||||
*/
|
||||
class Issuer
|
||||
{
|
||||
/**
|
||||
* The path to this issuers persistent storage.
|
||||
*/
|
||||
private String fPath;
|
||||
|
||||
/**
|
||||
* The next number to issue.
|
||||
*/
|
||||
private long fNext;
|
||||
|
||||
/**
|
||||
* Constructor for an already existing Issuer.
|
||||
* @param path The path to this issuers persistent store.
|
||||
*/
|
||||
public Issuer(String path)
|
||||
{
|
||||
fPath = path;
|
||||
try
|
||||
{
|
||||
DataInputStream in = new DataInputStream(new FileInputStream(fPath + ".new"));
|
||||
fNext = in.readLong();
|
||||
fNext += 257;
|
||||
in.close();
|
||||
save();
|
||||
return;
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
try
|
||||
{
|
||||
DataInputStream in = new DataInputStream(new FileInputStream(fPath));
|
||||
fNext = in.readLong();
|
||||
fNext += 257;
|
||||
in.close();
|
||||
save();
|
||||
return;
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
// Last resort.
|
||||
try
|
||||
{
|
||||
DataInputStream in = new DataInputStream(new FileInputStream(fPath + ".old"));
|
||||
fNext = in.readLong();
|
||||
fNext += 513;
|
||||
in.close();
|
||||
save();
|
||||
return;
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
// TODO Log this situation.
|
||||
throw new AVMException("Could not restore issuer" + fPath, ie);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rich constructor.
|
||||
* @param path The path to this issuers persistent store.
|
||||
* @param next The next number to issue.
|
||||
*/
|
||||
public Issuer(String path, long next)
|
||||
public Issuer(long next)
|
||||
{
|
||||
fPath = path;
|
||||
fNext = next;
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,42 +43,6 @@ class Issuer
|
||||
*/
|
||||
public synchronized long issue()
|
||||
{
|
||||
long val = fNext++;
|
||||
if (fNext % 128 == 0)
|
||||
{
|
||||
save();
|
||||
}
|
||||
return val;
|
||||
return fNext++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist this issuer.
|
||||
*/
|
||||
public void save()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileOutputStream fileOut = new FileOutputStream(fPath + ".new");
|
||||
DataOutputStream out = new DataOutputStream(fileOut);
|
||||
out.writeLong(fNext);
|
||||
out.flush();
|
||||
// Force data to physical storage.
|
||||
fileOut.getChannel().force(true);
|
||||
out.close();
|
||||
File from = new File(fPath);
|
||||
File to = new File(fPath + ".old");
|
||||
from.renameTo(to);
|
||||
from = new File(fPath + ".new");
|
||||
to = new File(fPath);
|
||||
from.renameTo(to);
|
||||
break;
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
// TODO Log this situation.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user