Patches to (hoefully) fix deadlock in BOB and revision bumpped to B
SusiMail JavaDoc additions.
This commit is contained in:
@ -46,7 +46,7 @@ public class doCMDS implements Runnable {
|
|||||||
|
|
||||||
// FIX ME
|
// FIX ME
|
||||||
// I need a better way to do versioning, but this will do for now.
|
// I need a better way to do versioning, but this will do for now.
|
||||||
public static final String BMAJ = "00", BMIN = "00", BREV = "01", BEXT = "-A";
|
public static final String BMAJ = "00", BMIN = "00", BREV = "01", BEXT = "-B";
|
||||||
public static final String BOBversion = BMAJ + "." + BMIN + "." + BREV + BEXT;
|
public static final String BOBversion = BMAJ + "." + BMIN + "." + BREV + BEXT;
|
||||||
private Socket server;
|
private Socket server;
|
||||||
private Properties props;
|
private Properties props;
|
||||||
|
@ -30,10 +30,8 @@ package net.i2p.BOB;
|
|||||||
*/
|
*/
|
||||||
public class nickname {
|
public class nickname {
|
||||||
|
|
||||||
private static final int maxWritersWaiting = 2;
|
|
||||||
private volatile Object[][] data;
|
private volatile Object[][] data;
|
||||||
private volatile int index, writersWaiting, readers;
|
private volatile int index, writersWaiting, readers;
|
||||||
private volatile boolean writingInProgress;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make initial NULL object
|
* make initial NULL object
|
||||||
@ -42,40 +40,35 @@ public class nickname {
|
|||||||
public nickname() {
|
public nickname() {
|
||||||
this.data = new Object[1][2];
|
this.data = new Object[1][2];
|
||||||
this.index = this.writersWaiting = this.readers = 0;
|
this.index = this.writersWaiting = this.readers = 0;
|
||||||
this.writingInProgress = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public void getReadLock() {
|
synchronized public void getReadLock() {
|
||||||
while(writingInProgress | (writersWaiting >= maxWritersWaiting)) {
|
while((writersWaiting != 0)) {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
} catch(InterruptedException ie) {
|
} catch(InterruptedException ie) {
|
||||||
}
|
}
|
||||||
readers++;
|
|
||||||
}
|
}
|
||||||
|
readers++;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public void releaseReadLock() {
|
synchronized public void releaseReadLock() {
|
||||||
readers--;
|
readers--;
|
||||||
if((readers == 0) & (writersWaiting > 0)) {
|
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
synchronized public void getWriteLock() {
|
synchronized public void getWriteLock() {
|
||||||
writersWaiting++;
|
writersWaiting++;
|
||||||
while((readers > 0) | writingInProgress) {
|
while(readers != 0 && writersWaiting != 1 ) {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
} catch(InterruptedException ie) {
|
} catch(InterruptedException ie) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writersWaiting--;
|
|
||||||
writingInProgress = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public void releaseWriteLock() {
|
synchronized public void releaseWriteLock() {
|
||||||
writingInProgress = false;
|
writersWaiting--;
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +77,7 @@ public class nickname {
|
|||||||
* @param key
|
* @param key
|
||||||
* @return an objects index
|
* @return an objects index
|
||||||
*/
|
*/
|
||||||
public synchronized int idx(Object key) {
|
public int idx(Object key) {
|
||||||
for(int i = 0; i < index; i++) {
|
for(int i = 0; i < index; i++) {
|
||||||
if(key.equals(data[i][0])) {
|
if(key.equals(data[i][0])) {
|
||||||
return i;
|
return i;
|
||||||
@ -98,7 +91,7 @@ public class nickname {
|
|||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
||||||
public synchronized void kill(Object key) {
|
public void kill(Object key) {
|
||||||
|
|
||||||
int i, j, k, l;
|
int i, j, k, l;
|
||||||
Object[][] olddata;
|
Object[][] olddata;
|
||||||
@ -131,7 +124,7 @@ public class nickname {
|
|||||||
* @param key
|
* @param key
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public synchronized void add(Object key, Object val) {
|
public void add(Object key, Object val) {
|
||||||
Object[][] olddata;
|
Object[][] olddata;
|
||||||
int i, j;
|
int i, j;
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -155,7 +148,7 @@ public class nickname {
|
|||||||
* @return Object
|
* @return Object
|
||||||
* @throws java.lang.RuntimeException
|
* @throws java.lang.RuntimeException
|
||||||
*/
|
*/
|
||||||
public synchronized Object get(Object key) throws RuntimeException {
|
public Object get(Object key) throws RuntimeException {
|
||||||
for(int i = 0; i < index; i++) {
|
for(int i = 0; i < index; i++) {
|
||||||
if(key.equals(data[i][0])) {
|
if(key.equals(data[i][0])) {
|
||||||
return data[i][1];
|
return data[i][1];
|
||||||
@ -170,7 +163,7 @@ public class nickname {
|
|||||||
* @param key
|
* @param key
|
||||||
* @return true if an object exists, else returns false
|
* @return true if an object exists, else returns false
|
||||||
*/
|
*/
|
||||||
public synchronized boolean exists(Object key) {
|
public boolean exists(Object key) {
|
||||||
for(int i = 0; i < index; i++) {
|
for(int i = 0; i < index; i++) {
|
||||||
if(key.equals(data[i][0])) {
|
if(key.equals(data[i][0])) {
|
||||||
return true;
|
return true;
|
||||||
@ -186,7 +179,7 @@ public class nickname {
|
|||||||
* @return an indexed Object
|
* @return an indexed Object
|
||||||
* @throws java.lang.RuntimeException
|
* @throws java.lang.RuntimeException
|
||||||
*/
|
*/
|
||||||
public synchronized Object getnext(int i) throws RuntimeException {
|
public Object getnext(int i) throws RuntimeException {
|
||||||
if(i < index && i > -1) {
|
if(i < index && i > -1) {
|
||||||
return data[i][1];
|
return data[i][1];
|
||||||
}
|
}
|
||||||
@ -196,7 +189,7 @@ public class nickname {
|
|||||||
/**
|
/**
|
||||||
* @return the count of how many objects
|
* @return the count of how many objects
|
||||||
*/
|
*/
|
||||||
public synchronized int getcount() {
|
public int getcount() {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,8 @@ public class Base64 implements Encoding {
|
|||||||
return "base64";
|
return "base64";
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param string
|
|
||||||
* @return
|
* @return
|
||||||
|
* @throws EncodingException
|
||||||
*/
|
*/
|
||||||
public String encode( byte in[] ) throws EncodingException
|
public String encode( byte in[] ) throws EncodingException
|
||||||
{
|
{
|
||||||
@ -172,7 +172,7 @@ public class Base64 implements Encoding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param str
|
* @param text
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ReadBuffer decode(String text) throws DecodingException {
|
public ReadBuffer decode(String text) throws DecodingException {
|
||||||
|
@ -36,37 +36,44 @@ public interface Encoding {
|
|||||||
*
|
*
|
||||||
* @param in
|
* @param in
|
||||||
* @return
|
* @return
|
||||||
|
* @throws EncodingException
|
||||||
*/
|
*/
|
||||||
public String encode( byte in[] ) throws EncodingException;
|
public String encode( byte in[] ) throws EncodingException;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str
|
||||||
* @return
|
* @return
|
||||||
|
* @throws EncodingException
|
||||||
*/
|
*/
|
||||||
public String encode( String str ) throws EncodingException;
|
public String encode( String str ) throws EncodingException;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param in
|
* @param in
|
||||||
* @return
|
* @return
|
||||||
|
* @throws DecodingException
|
||||||
*/
|
*/
|
||||||
public ReadBuffer decode( byte in[] ) throws DecodingException;
|
public ReadBuffer decode( byte in[] ) throws DecodingException;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param in
|
* @param in
|
||||||
* @param size
|
* @param offset
|
||||||
|
* @param length
|
||||||
* @return
|
* @return
|
||||||
|
* @throws DecodingException
|
||||||
*/
|
*/
|
||||||
public ReadBuffer decode( byte in[], int offset, int length ) throws DecodingException;
|
public ReadBuffer decode( byte in[], int offset, int length ) throws DecodingException;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str
|
||||||
* @return
|
* @return
|
||||||
|
* @throws DecodingException
|
||||||
*/
|
*/
|
||||||
public ReadBuffer decode( String str ) throws DecodingException;
|
public ReadBuffer decode( String str ) throws DecodingException;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param in
|
* @param in
|
||||||
* @return
|
* @return
|
||||||
|
* @throws DecodingException
|
||||||
*/
|
*/
|
||||||
public ReadBuffer decode( ReadBuffer in ) throws DecodingException;
|
public ReadBuffer decode( ReadBuffer in ) throws DecodingException;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user