-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature_improve_netkeys'
- Loading branch information
Showing
205 changed files
with
3,863 additions
and
1,086 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.cowboycoders</groupId> | ||
<artifactId>jformica-parent</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>jformica-core</artifactId> | ||
<packaging>jar</packaging> | ||
<name>jformica-core</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<version>1.9.5</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.vidageek</groupId> | ||
<artifactId>mirror</artifactId> | ||
<version>1.5.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
107 changes: 107 additions & 0 deletions
107
jformica-core/src/main/java/org/cowboycoders/ant/Network.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.cowboycoders.ant; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* Encapsulates an ant network | ||
* @author will | ||
* | ||
*/ | ||
public class Network { | ||
|
||
/** | ||
* Id of network (functions as uuid) | ||
*/ | ||
private int number; | ||
|
||
private AtomicInteger refCount = new AtomicInteger(); | ||
|
||
/** | ||
* Ant network key associated with this network | ||
*/ | ||
private NetworkKey networkKey; | ||
|
||
private NetworkListener networkListener; | ||
|
||
/** | ||
* | ||
* @param number the internal ant network id | ||
* @param networkKey key associated with this network | ||
* @param networkListener used to register for notifications | ||
*/ | ||
protected Network(int number, NetworkKey networkKey, | ||
NetworkListener networkListener) { | ||
super(); | ||
this.number = number; | ||
this.networkKey = networkKey; | ||
this.networkListener = networkListener; | ||
} | ||
|
||
protected Network(Network network) { | ||
this(network.getNumber(),network.getNetworkKey(),network.getNetworkListener()); | ||
refCount = network.refCount; | ||
} | ||
|
||
/** | ||
* Register that you are using this network and it should not be reassigned. | ||
*/ | ||
protected void use() { | ||
refCount.incrementAndGet(); | ||
} | ||
|
||
/** | ||
* Should be called when you no longer wish to use this network. Should only be called once, so | ||
* null your reference after calling. | ||
*/ | ||
public void free() { | ||
if (refCount.decrementAndGet() <= 0 && networkListener != null ) { | ||
networkListener.onFree(this); | ||
} | ||
} | ||
|
||
/** | ||
* Provides the internal ant network | ||
* @return internal ant network id | ||
*/ | ||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
/** | ||
* Current {@link NetworkKey} associated with this network or null if no association exists. | ||
* @return | ||
*/ | ||
public NetworkKey getNetworkKey() { | ||
return networkKey; | ||
} | ||
|
||
protected NetworkListener getNetworkListener() { | ||
return networkListener; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + number; | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
Network other = (Network) obj; | ||
if (number != other.number) | ||
return false; | ||
return true; | ||
} | ||
|
||
|
||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
jformica-core/src/main/java/org/cowboycoders/ant/NetworkAllocationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.cowboycoders.ant; | ||
|
||
/** | ||
* Indicates that the network could not be allocated | ||
* @author will | ||
* | ||
*/ | ||
public class NetworkAllocationException extends AntError { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public NetworkAllocationException() { | ||
super(); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
public NetworkAllocationException(String detailMessage, Throwable throwable) { | ||
super(detailMessage, throwable); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
public NetworkAllocationException(String detailMessage) { | ||
super(detailMessage); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
public NetworkAllocationException(Throwable throwable) { | ||
super(throwable); | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
|
||
|
||
} |
68 changes: 68 additions & 0 deletions
68
jformica-core/src/main/java/org/cowboycoders/ant/NetworkHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.cowboycoders.ant; | ||
|
||
/** | ||
* Ensures a network reference can only be freed once | ||
* @author will | ||
* | ||
*/ | ||
public class NetworkHandle extends Network { | ||
|
||
private boolean freed = false; | ||
|
||
protected NetworkHandle(Network network) { | ||
super(network); | ||
// increment reference count | ||
use(); | ||
} | ||
|
||
|
||
@Override | ||
public synchronized void free() { | ||
// if has been freed | ||
checkState(); | ||
super.free(); | ||
freed = true; | ||
} | ||
|
||
|
||
private synchronized void checkState() { | ||
if (freed) { | ||
throw new IllegalStateException("Trying to use a network which has been freed"); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
protected synchronized void use() { | ||
checkState(); | ||
super.use(); | ||
} | ||
|
||
|
||
@Override | ||
public synchronized int getNumber() { | ||
checkState(); | ||
return super.getNumber(); | ||
} | ||
|
||
|
||
@Override | ||
public synchronized NetworkKey getNetworkKey() { | ||
checkState(); | ||
return super.getNetworkKey(); | ||
} | ||
|
||
|
||
@Override | ||
protected synchronized NetworkListener getNetworkListener() { | ||
checkState(); | ||
return super.getNetworkListener(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.