You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by si...@apache.org on 2010/12/29 12:15:20 UTC
svn commit: r1053612 - in /incubator/river/jtsk/skunk/generics/src:
com/sun/jini/example/browser/ com/sun/jini/outrigger/ net/jini/space/
Author: sijskes
Date: Wed Dec 29 11:15:20 2010
New Revision: 1053612
URL: http://svn.apache.org/viewvc?rev=1053612&view=rev
Log:
RIVER-384 applied patch javaspace-generics-patch.txt
Modified:
incubator/river/jtsk/skunk/generics/src/com/sun/jini/example/browser/SpaceBrowser.java
incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/MatchSetProxy.java
incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/SpaceProxy2.java
incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace.java
incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace05.java
incubator/river/jtsk/skunk/generics/src/net/jini/space/MatchSet.java
Modified: incubator/river/jtsk/skunk/generics/src/com/sun/jini/example/browser/SpaceBrowser.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/generics/src/com/sun/jini/example/browser/SpaceBrowser.java?rev=1053612&r1=1053611&r2=1053612&view=diff
==============================================================================
--- incubator/river/jtsk/skunk/generics/src/com/sun/jini/example/browser/SpaceBrowser.java (original)
+++ incubator/river/jtsk/skunk/generics/src/com/sun/jini/example/browser/SpaceBrowser.java Wed Dec 29 11:15:20 2010
@@ -115,7 +115,7 @@ class SpaceBrowser extends JFrame {
List acc = new java.util.LinkedList();
if (proxy instanceof JavaSpace05) {
MatchSet set =
- ((JavaSpace05) proxy).contents(Collections.singleton(null),
+ ((JavaSpace05) proxy).contents(Collections.<Entry>singleton(null),
null, Lease.ANY, Integer.MAX_VALUE);
Lease lease = set.getLease();
if (lease != null) {
Modified: incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/MatchSetProxy.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/MatchSetProxy.java?rev=1053612&r1=1053611&r2=1053612&view=diff
==============================================================================
--- incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/MatchSetProxy.java (original)
+++ incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/MatchSetProxy.java Wed Dec 29 11:15:20 2010
@@ -37,7 +37,7 @@ import net.jini.space.MatchSet;
* Note, there is no way to serialize or otherwise copy instances of
* this class so the default equals implementation should suffice.
*/
-class MatchSetProxy implements MatchSet {
+class MatchSetProxy<E extends Entry> implements MatchSet<E> {
/** The remote server this proxy works with. */
final private OutriggerServer space;
@@ -75,7 +75,7 @@ class MatchSetProxy implements MatchSet
return lease;
}
- public Entry next() throws RemoteException, UnusableEntryException {
+ public E next() throws RemoteException, UnusableEntryException {
if (i >= reps.length) {
// Fetch another batch
i = 0;
@@ -89,7 +89,7 @@ class MatchSetProxy implements MatchSet
lastRepReturned = reps[i++];
final Entry rslt = lastRepReturned.entry();
unpackFailure = false;
- return rslt;
+ return (E) rslt;
}
public Entry getSnapshot() {
Modified: incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/SpaceProxy2.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/SpaceProxy2.java?rev=1053612&r1=1053611&r2=1053612&view=diff
==============================================================================
--- incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/SpaceProxy2.java (original)
+++ incubator/river/jtsk/skunk/generics/src/com/sun/jini/outrigger/SpaceProxy2.java Wed Dec 29 11:15:20 2010
@@ -301,7 +301,7 @@ class SpaceProxy2 implements JavaSpace05
leaseData[0]);
}
- public Entry read(Entry tmpl, Transaction txn, long timeout)
+ public <E extends Entry> E read(E tmpl, Transaction txn, long timeout)
throws UnusableEntryException, TransactionException,
InterruptedException, RemoteException
{
@@ -324,7 +324,7 @@ class SpaceProxy2 implements JavaSpace05
throw new AssertionError("space.read() returned null");
} else if (rslt instanceof EntryRep) {
// Got an answer, return it
- return entryFrom((EntryRep)rslt);
+ return (E) entryFrom((EntryRep)rslt);
} else if (rslt instanceof OutriggerServer.QueryCookie) {
/* Will still want to go on if there is time, but pass
* the new cookie
@@ -348,7 +348,7 @@ class SpaceProxy2 implements JavaSpace05
}
// inherit doc comment, use internal routine for common code
- public Entry readIfExists(Entry tmpl, Transaction txn, long timeout)
+ public <E extends Entry> E readIfExists(E tmpl, Transaction txn, long timeout)
throws UnusableEntryException, TransactionException,
InterruptedException, RemoteException
{
@@ -372,7 +372,7 @@ class SpaceProxy2 implements JavaSpace05
return null;
} else if (rslt instanceof EntryRep) {
// Got an answer, return it
- return entryFrom((EntryRep)rslt);
+ return (E) entryFrom((EntryRep)rslt);
} else if (rslt instanceof OutriggerServer.QueryCookie) {
/* Will still want to go on if there is time, but pass
* the new cookie
@@ -396,7 +396,8 @@ class SpaceProxy2 implements JavaSpace05
}
// inherit doc comment, use internal routine for common code
- public Entry take(Entry tmpl, Transaction txn, long timeout)
+ @SuppressWarnings("unchecked")
+ public <E extends Entry> E take(E tmpl, Transaction txn, long timeout)
throws UnusableEntryException, TransactionException,
InterruptedException, RemoteException
{
@@ -419,7 +420,7 @@ class SpaceProxy2 implements JavaSpace05
throw new AssertionError("space.take() returned null");
} else if (rslt instanceof EntryRep) {
// Got an answer, return it
- return entryFrom((EntryRep)rslt);
+ return (E) entryFrom((EntryRep)rslt);
} else if (rslt instanceof OutriggerServer.QueryCookie) {
/* Will still want to go on if there is time, but pass
* the new cookie
@@ -443,7 +444,7 @@ class SpaceProxy2 implements JavaSpace05
}
// inherit doc comment, use internal routine for common code
- public Entry takeIfExists(Entry tmpl, Transaction txn, long timeout)
+ public <E extends Entry> E takeIfExists(E tmpl, Transaction txn, long timeout)
throws UnusableEntryException, TransactionException,
InterruptedException, RemoteException
{
@@ -467,7 +468,7 @@ class SpaceProxy2 implements JavaSpace05
return null;
} else if (rslt instanceof EntryRep) {
// Got an answer, return it
- return entryFrom((EntryRep)rslt);
+ return (E) entryFrom((EntryRep)rslt);
} else if (rslt instanceof OutriggerServer.QueryCookie) {
/* Will still want to go on if there is time, but pass
* the new cookie
@@ -507,30 +508,25 @@ class SpaceProxy2 implements JavaSpace05
return space.notify(repFor(tmpl), txn, listener, lease, handback);
}
- public List write(List entries, Transaction txn, List leaseDurations)
+ public List<Lease> write(List<? extends Entry> entries, Transaction txn, List<Long> leaseDurations)
throws RemoteException, TransactionException
{
final long[] leases = new long[leaseDurations.size()];
int j = 0;
- for (Iterator i=leaseDurations.iterator(); i.hasNext(); ) {
- final Object l = i.next();
-
- if (l == null)
- throw new NullPointerException(
- "leaseDurations contatins a null element");
-
- if (!(l instanceof Long))
- throw new IllegalArgumentException(
- "leaseDurations contatins an element which is not a Long");
+ for (Long l : leaseDurations) {
+ if (l == null) {
+ throw new NullPointerException(
+ "leaseDurations contatins a null element");
+ }
- leases[j++] = ((Long)l).longValue();
+ leases[j++] = l.longValue();
}
long[] leaseData = space.write(repFor(entries, "entries"), txn, leases);
if (leaseData == null)
throw new AssertionError("space.write<multiple> returned null");
- final List rslt = new ArrayList(leaseData.length/3);
+ final List<Lease> rslt = new ArrayList<Lease>(leaseData.length/3);
try {
int m=0;
while (m<leaseData.length) {
@@ -548,7 +544,7 @@ class SpaceProxy2 implements JavaSpace05
return rslt;
}
- public Collection take(Collection tmpls, Transaction txn,
+ public <E extends Entry> Collection<E> take(Collection<E> tmpls, Transaction txn,
long timeout, long maxEntries)
throws UnusableEntriesException, TransactionException, RemoteException
{
@@ -583,15 +579,15 @@ class SpaceProxy2 implements JavaSpace05
} else if (rslt instanceof EntryRep[]) {
EntryRep[] reps = (EntryRep[])rslt;
// Got an answer, return it
- final Collection entries = new LinkedList();
- Collection exceptions = null;
+ final Collection<E> entries = new LinkedList<E>();
+ Collection<UnusableEntryException> exceptions = null;
for (int i=0;i<reps.length;i++) {
try {
- entries.add(entryFrom(reps[i]));
+ entries.add((E) entryFrom(reps[i]));
} catch (UnusableEntryException e) {
if (exceptions == null)
- exceptions = new LinkedList();
+ exceptions = new LinkedList<UnusableEntryException>();
exceptions.add(e);
}
@@ -623,11 +619,11 @@ class SpaceProxy2 implements JavaSpace05
/* If we get here then there must not have been any entries available
* to us before the endTime.
*/
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
public EventRegistration
- registerForAvailabilityEvent(Collection tmpls,
+ registerForAvailabilityEvent(Collection<? extends Entry> tmpls,
Transaction txn,
boolean visibilityOnly,
RemoteEventListener listener,
@@ -642,7 +638,7 @@ class SpaceProxy2 implements JavaSpace05
// inherit doc comment
- public MatchSet contents(Collection tmpls,
+ public <E extends Entry> MatchSet<E> contents(Collection<E> tmpls,
Transaction txn,
long leaseDuration,
long maxEntries)
@@ -650,7 +646,7 @@ class SpaceProxy2 implements JavaSpace05
{
final MatchSetData msd =
space.contents(repFor(tmpls, "tmpls"), txn, leaseDuration, maxEntries);
- return new MatchSetProxy(msd, this, space);
+ return new MatchSetProxy<E>(msd, this, space);
}
/* We break up lease creation into two methods. newLease takes
@@ -705,18 +701,18 @@ class SpaceProxy2 implements JavaSpace05
return now + timeout;
}
- static EntryRep[] repFor(Collection entries, String argName)
+ static EntryRep[] repFor(Collection<? extends Entry> entries, String argName)
throws MarshalException
{
final EntryRep[] reps = new EntryRep[entries.size()];
int j = 0;
- for (Iterator i=entries.iterator(); i.hasNext(); ) {
- final Object e = i.next();
- if (!(e == null || e instanceof Entry))
+ for (Iterator<? extends Entry> i=entries.iterator(); i.hasNext(); ) {
+ final Entry e = i.next();
+ if (!(e == null))
throw new IllegalArgumentException(
argName + " contatins an element which is not an Entry");
- reps[j++] = repFor((Entry)e);
+ reps[j++] = repFor(e);
}
return reps;
Modified: incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace.java?rev=1053612&r1=1053611&r2=1053612&view=diff
==============================================================================
--- incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace.java (original)
+++ incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace.java Wed Dec 29 11:15:20 2010
@@ -78,6 +78,7 @@ public interface JavaSpace {
* timeout of <code>NO_WAIT</code> means to wait
* no time at all; this is equivalent to a wait
* of zero.
+ * @param <E> The type of the template is the same as the return type
*
* @return a copy of the entry read from the space
* @throws UnusableEntryException if any serialized field of the entry
@@ -88,7 +89,7 @@ public interface JavaSpace {
* @throws RemoteException if a communication error occurs
* @throws IllegalArgumentException if a negative timeout value is used
*/
- Entry read(Entry tmpl, Transaction txn, long timeout)
+ <E extends Entry> E read(E tmpl, Transaction txn, long timeout)
throws UnusableEntryException, TransactionException,
InterruptedException, RemoteException;
@@ -110,6 +111,7 @@ public interface JavaSpace {
* timeout of <code>NO_WAIT</code> means to wait
* no time at all; this is equivalent to a wait
* of zero.
+ * @param <E> The type of the template is the same as the return type
*
* @return a copy of the entry read from the space
* @throws UnusableEntryException if any serialized field of the entry
@@ -121,7 +123,7 @@ public interface JavaSpace {
* @throws IllegalArgumentException if a negative timeout value is used
* @see #read
*/
- Entry readIfExists(Entry tmpl, Transaction txn, long timeout)
+ <E extends Entry> E readIfExists(E tmpl, Transaction txn, long timeout)
throws UnusableEntryException, TransactionException,
InterruptedException, RemoteException;
@@ -140,6 +142,7 @@ public interface JavaSpace {
* timeout of <code>NO_WAIT</code> means to wait
* no time at all; this is equivalent to a wait
* of zero.
+ * @param <E> The type of the template is the same as the return type
*
* @return the entry taken from the space
* @throws UnusableEntryException if any serialized field of the entry
@@ -151,7 +154,7 @@ public interface JavaSpace {
* @throws IllegalArgumentException if a negative timeout value is used
* @see #read
*/
- Entry take(Entry tmpl, Transaction txn, long timeout)
+ <E extends Entry> E take(E tmpl, Transaction txn, long timeout)
throws UnusableEntryException, TransactionException,
InterruptedException, RemoteException;
@@ -173,6 +176,7 @@ public interface JavaSpace {
* timeout of <code>NO_WAIT</code> means to wait
* no time at all; this is equivalent to a wait
* of zero.
+ * @param <E> The type of the template is the same as the return type
*
* @return the entry taken from the space
* @throws UnusableEntryException if any serialized field of the entry
@@ -184,7 +188,7 @@ public interface JavaSpace {
* @throws IllegalArgumentException if a negative timeout value is used
* @see #read
*/
- Entry takeIfExists(Entry tmpl, Transaction txn, long timeout)
+ <E extends Entry> E takeIfExists(E tmpl, Transaction txn, long timeout)
throws UnusableEntryException, TransactionException,
InterruptedException, RemoteException;
Modified: incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace05.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace05.java?rev=1053612&r1=1053611&r2=1053612&view=diff
==============================================================================
--- incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace05.java (original)
+++ incubator/river/jtsk/skunk/generics/src/net/jini/space/JavaSpace05.java Wed Dec 29 11:15:20 2010
@@ -149,9 +149,9 @@ public interface JavaSpace05 extends Jav
* or <code>leaseDurations</code> is <code>null</code>
* or contains a <code>null</code> value
*/
- public List write(List entries,
+ public List<Lease> write(List<? extends Entry> entries,
Transaction txn,
- List leaseDurations)
+ List<Long> leaseDurations)
throws TransactionException, RemoteException;
/**
@@ -266,6 +266,8 @@ public interface JavaSpace05 extends Jav
* become available
* @param maxEntries the maximum number of entries that may be
* taken by this method
+ * @param <E> The type of the template is the same as the returned entries
+ *
* @return a <code>Collection</code> that contains a copy of each
* <code>Entry</code> taken from the space by this
* method. The space will not keep a reference to
@@ -283,10 +285,10 @@ public interface JavaSpace05 extends Jav
* <code>maxEntries</code> is non-positive
* @throws NullPointerException if <code>tmpls</code> is null
*/
- public Collection take(Collection tmpls,
+ public <E extends Entry> Collection<E> take(Collection<E> tmpls,
Transaction txn,
- long timeout,
- long maxEntries)
+ long timeout,
+ long maxEntries)
throws UnusableEntriesException, TransactionException,
RemoteException;
@@ -388,6 +390,8 @@ public interface JavaSpace05 extends Jav
* @param maxEntries the maximum number of entries to remove
* from the set via {@link MatchSet#next MatchSet.next}
* calls
+ * @param <E> The type of the template is the same as the type returned by the MatchSet.
+ *
* @return A proxy to the newly created {@linkplain MatchSet match set}
* @throws TransactionException if <code>txn</code> is
* non-<code>null</code> and is not usable by the
@@ -402,7 +406,7 @@ public interface JavaSpace05 extends Jav
* @throws NullPointerException if <code>tmpls</code> is
* <code>null</code>
*/
- public MatchSet contents(Collection tmpls,
+ public <E extends Entry> MatchSet<E> contents(Collection<E> tmpls,
Transaction txn,
long leaseDuration,
long maxEntries)
@@ -531,7 +535,7 @@ public interface JavaSpace05 extends Jav
* <code>listener</code> is <code>null</code>
*/
public EventRegistration
- registerForAvailabilityEvent(Collection tmpls,
+ registerForAvailabilityEvent(Collection<? extends Entry> tmpls,
Transaction txn,
boolean visibilityOnly,
RemoteEventListener listener,
Modified: incubator/river/jtsk/skunk/generics/src/net/jini/space/MatchSet.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/generics/src/net/jini/space/MatchSet.java?rev=1053612&r1=1053611&r2=1053612&view=diff
==============================================================================
--- incubator/river/jtsk/skunk/generics/src/net/jini/space/MatchSet.java (original)
+++ incubator/river/jtsk/skunk/generics/src/net/jini/space/MatchSet.java Wed Dec 29 11:15:20 2010
@@ -17,13 +17,13 @@
*/
package net.jini.space;
-import java.rmi.RemoteException;
import java.rmi.NoSuchObjectException;
+import java.rmi.RemoteException;
+
+import net.jini.core.constraint.RemoteMethodControl;
import net.jini.core.entry.Entry;
import net.jini.core.entry.UnusableEntryException;
import net.jini.core.lease.Lease;
-import net.jini.core.lease.UnknownLeaseException;
-import net.jini.core.constraint.RemoteMethodControl;
/**
* A collection of {@link Entry} instances to be incrementally
@@ -110,7 +110,7 @@ import net.jini.core.constraint.RemoteMe
* Method Invocation remote method semantics.
*
* @since 2.1 */
-public interface MatchSet {
+public interface MatchSet<E extends Entry> {
/**
* Removes one <code>Entry</code> from the match set and
* returns a copy to the caller. Returns <code>null</code> if
@@ -140,7 +140,7 @@ public interface MatchSet {
* <code>Entry</code> was removed from the match set
* because of this call
*/
- public Entry next() throws RemoteException, UnusableEntryException;
+ public E next() throws RemoteException, UnusableEntryException;
/**
* Returns a proxy to the {@link Lease} associated with this