river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1719763 - in /river/jtsk/trunk/src: net/jini/discovery/ net/jini/export/ net/jini/lease/ net/jini/lookup/ org/apache/river/jeri/internal/http/ org/apache/river/mahalo/log/ org/apache/river/norm/ org/apache/river/reggie/ org/apache/river/st...
Date Sun, 13 Dec 2015 05:09:58 GMT
Author: peter_firmstone
Date: Sun Dec 13 05:09:57 2015
New Revision: 1719763

URL: http://svn.apache.org/viewvc?rev=1719763&view=rev
Log:
RIVER-431 Findbugs static analysis revealed some synchronization bugs remained, these have
been fixed along with some other bugs.  Note that TaskManager has not been fixed as it is
deprecated.  Note, not all bugs identified by Findbugs have been fixed, bugs that remain are
relatively minor and will be fixed in a following release.

Modified:
    river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscovery.java
    river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscoveryManager.java
    river/jtsk/trunk/src/net/jini/discovery/AbstractLookupLocatorDiscovery.java
    river/jtsk/trunk/src/net/jini/discovery/Constants.java
    river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java
    river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java
    river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java
    river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java
    river/jtsk/trunk/src/net/jini/export/ServerContext.java
    river/jtsk/trunk/src/net/jini/lease/LeaseRenewalManager.java
    river/jtsk/trunk/src/net/jini/lookup/JoinManager.java
    river/jtsk/trunk/src/org/apache/river/jeri/internal/http/Header.java
    river/jtsk/trunk/src/org/apache/river/mahalo/log/MultiLogManager.java
    river/jtsk/trunk/src/org/apache/river/mahalo/log/SimpleLogFile.java
    river/jtsk/trunk/src/org/apache/river/norm/LeaseSet.java
    river/jtsk/trunk/src/org/apache/river/reggie/RegistrarImpl.java
    river/jtsk/trunk/src/org/apache/river/start/ProxyVerifier.java

Modified: river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscovery.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscovery.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscovery.java Sun Dec 13 05:09:57
2015
@@ -348,7 +348,7 @@ abstract class AbstractLookupDiscovery i
 			    DiscoveryEvent e =
 				new DiscoveryEvent
                                         ( AbstractLookupDiscovery.this,
-                                          deepCopy((HashMap)task.groupsMap) );
+                                          deepCopy(task.groupsMap) );
                             /* Log the event info about the lookup(s) */
                             if(     firstListener
                                 && (logger.isLoggable(Level.FINEST)) )
@@ -1683,13 +1683,13 @@ abstract class AbstractLookupDiscovery i
         if (listeners.indexOf(l) >= 0) return; //already have this listener
         listeners.add(l);
         if (registrars.isEmpty()) return;//nothing to send the new listener
-        HashMap groupsMap = new HashMap(registrars.size());
-        Iterator iter = registrars.values().iterator();
+        Map<ServiceRegistrar,String[]> groupsMap = new HashMap(registrars.size());
+        Iterator<UnicastResponse> iter = registrars.values().iterator();
         while (iter.hasNext()) {
-            UnicastResponse resp = (UnicastResponse)iter.next();
+            UnicastResponse resp = iter.next();
             groupsMap.put(resp.getRegistrar(),resp.getGroups());
         }
-        List list = new ArrayList(1);
+        List<DiscoveryListener> list = new ArrayList<DiscoveryListener>(1);
         list.add(l);
         addNotify(list, groupsMap, DISCOVERED);
     }//end addDiscoveryListener
@@ -2625,15 +2625,15 @@ abstract class AbstractLookupDiscovery i
      *  @return clone of the input map, and of each key-value pair contained
      *          in the input map
      */
-    private Map deepCopy(HashMap groupsMap) {
+    private Map<ServiceRegistrar, String[]> deepCopy(Map<ServiceRegistrar,String[]>
groupsMap) {
         /* clone the input HashMap */
-        HashMap newMap = (HashMap)(groupsMap.clone());
+        Map<ServiceRegistrar,String[]> newMap = new HashMap<ServiceRegistrar,String[]>(groupsMap);
         /* clone the values of each mapping in place */
-        Set eSet = newMap.entrySet();
-        for(Iterator itr = eSet.iterator(); itr.hasNext(); ) {
-            Map.Entry pair = (Map.Entry)itr.next();
+        Set<Map.Entry<ServiceRegistrar,String[]>> eSet = newMap.entrySet();
+        for(Iterator<Map.Entry<ServiceRegistrar,String[]>> itr = eSet.iterator();
itr.hasNext(); ) {
+            Map.Entry<ServiceRegistrar,String[]> pair = itr.next();
             /* only need to clone the value of the order pair */
-            pair.setValue( ((String[])pair.getValue()).clone() );
+            pair.setValue( pair.getValue().clone() );
         }
         return newMap;
     }//end deepCopy

Modified: river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscoveryManager.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscoveryManager.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscoveryManager.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/AbstractLookupDiscoveryManager.java Sun Dec 13
05:09:57 2015
@@ -396,16 +396,17 @@ abstract class AbstractLookupDiscoveryMa
          */
 	public void discovered(DiscoveryEvent e) {
             ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
-            Map groupsMap = e.getGroups();
+            Map<ServiceRegistrar, String[]> groupsMap = e.getGroups();
             int len = proxys.length;
-            HashMap discoveredGroupsMap = new HashMap(len);
+            Map<ServiceRegistrar, String[]> discoveredGroupsMap 
+                    = new HashMap<ServiceRegistrar, String[]>(len);
             discoveredSetAddLock.lock();
             try {
                 for(int i=0; i<len; i++) {
                         ProxyReg reg = findReg(proxys[i]);
                         if(reg == null) {//newly discovered, send event
-                            reg = new ProxyReg(proxys[i],
-                                              (String[])(groupsMap.get(proxys[i])),
+                            reg = new ProxyReg(proxys[i], 
+                                               groupsMap.get(proxys[i]),
                                                FROM_LOCATOR);
                             discoveredSet.add(reg);
                             discoveredGroupsMap.put(proxys[i],
@@ -501,16 +502,16 @@ abstract class AbstractLookupDiscoveryMa
          *  </pre>
          */
 	public void discarded(DiscoveryEvent e) {
-	    ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
-            Map groupsMap = e.getGroups();
+	    ServiceRegistrar[] proxys = e.getRegistrars();
+            Map<ServiceRegistrar, String[]> groupsMap = e.getGroups();
             int len = proxys.length;
-            HashMap discardedGroupsMap = new HashMap(len);
+            Map<ServiceRegistrar, String[]> discardedGroupsMap 
+                    = new HashMap<ServiceRegistrar, String[]>(len);
 	    for(int i=0; i<len; i++) {
                     ProxyReg reg = findReg(proxys[i]);
                     if(reg != null) {
-                        String[] newGroups = (String[])groupsMap.get
-                                                                   (reg.proxy);
-                        if( removeDiscoveredSet(reg,FROM_LOCATOR) ) {
+                        String[] newGroups = groupsMap.get(reg.proxy);
+                        if ( removeDiscoveredSet(reg,FROM_LOCATOR) ) {
                             /* Locator discovery only, always send discarded */
                             discardedGroupsMap.put(reg.proxy,newGroups);
                         } else {//group and loc discovery
@@ -575,25 +576,26 @@ abstract class AbstractLookupDiscoveryMa
          */
 	public void discovered(DiscoveryEvent e) {
             ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
-            Map groupsMap = e.getGroups();
+            Map<ServiceRegistrar, String[]> groupsMap = e.getGroups();
             int len = proxys.length;
-            HashMap discoveredGroupsMap = new HashMap(len);
-            HashMap changedGroupsMap    = new HashMap(len);
+            Map<ServiceRegistrar, String[]> discoveredGroupsMap 
+                    = new HashMap<ServiceRegistrar, String[]>(len);
+            Map<ServiceRegistrar, String[]> changedGroupsMap    
+                    = new HashMap<ServiceRegistrar, String[]>(len);
             discoveredSetAddLock.lock();
             try {
                 for(int i=0; i<len; i++) {
                     ProxyReg reg = findReg(proxys[i]);
                     if(reg == null) {//newly discovered, send discovered event
                         reg = new ProxyReg(proxys[i],
-                                          (String[])(groupsMap.get(proxys[i])),
+                                           groupsMap.get(proxys[i]),
                                            FROM_GROUP);
                         discoveredSet.add(reg);
                         discoveredGroupsMap.put(proxys[i],
                                                 groupsMap.get(proxys[i]));
                     } else {//previously discovered by group, by loc or by both
                         String[] oldGroups = reg.getMemberGroups();
-                        String[] newGroups = (String[])groupsMap.get
-                                                                  (reg.proxy);
+                        String[] newGroups = groupsMap.get(reg.proxy);
                         if( groupSetsEqual(oldGroups,newGroups) ) {//by loc
                             reg.addFrom(FROM_GROUP);//send no event
                         } else {//by group or by both, send changed event
@@ -734,15 +736,16 @@ abstract class AbstractLookupDiscoveryMa
          */
 	public void discarded(DiscoveryEvent e) {
 	    ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
-            Map groupsMap = e.getGroups();
+            Map<ServiceRegistrar, String[]> groupsMap = e.getGroups();
             int len = proxys.length;
-            HashMap discardedGroupsMap = new HashMap(len);
-            HashMap changedGroupsMap   = new HashMap(len);
+            Map<ServiceRegistrar, String[]> discardedGroupsMap 
+                    = new HashMap<ServiceRegistrar, String[]>(len);
+            Map<ServiceRegistrar, String[]> changedGroupsMap   
+                    = new HashMap<ServiceRegistrar, String[]>(len);
 	    for(int i=0; i<len; i++) {
                     ProxyReg reg = findReg(proxys[i]);
                     if(reg != null) {
-                        String[] newGroups = (String[])groupsMap.get
-                                                                   (reg.proxy);
+                        String[] newGroups = groupsMap.get(reg.proxy);
                         if( removeDiscoveredSet(reg,FROM_GROUP) ) {
                             /* group discovery only, always send discarded */
                             discardedGroupsMap.put(reg.proxy,newGroups);
@@ -776,14 +779,14 @@ abstract class AbstractLookupDiscoveryMa
         public void changed(DiscoveryEvent e) {
             /* update the groups of each changed registrar */
             ServiceRegistrar[] proxys = (ServiceRegistrar[])e.getRegistrars();
-            Map groupsMap = e.getGroups();
+            Map<ServiceRegistrar, String[]> groupsMap = e.getGroups();
             int len = proxys.length;
-            HashMap changedGroupsMap = new HashMap(len);
+            Map<ServiceRegistrar, String[]> changedGroupsMap 
+                    = new HashMap<ServiceRegistrar, String[]>(len);
 	    for(int i=0; i<len; i++) {
                 ProxyReg reg = findReg(proxys[i]);
                 if(reg != null) {//previously discovered
-                    String[] newGroups = (String[])groupsMap.get
-                                                               (reg.proxy);
+                    String[] newGroups = groupsMap.get(reg.proxy);
                     reg.setMemberGroups(newGroups);
                     changedGroupsMap.put(reg.proxy,newGroups);
                 }//endif
@@ -1094,7 +1097,7 @@ abstract class AbstractLookupDiscoveryMa
         
         listeners.add(listener);
         if (discoveredSet.isEmpty()) return;
-        HashMap groupsMap = new HashMap(discoveredSet.size());
+        Map<ServiceRegistrar, String[]> groupsMap = new HashMap<ServiceRegistrar,
String[]>(discoveredSet.size());
         Iterator<ProxyReg> it = discoveredSet.iterator();
         while (it.hasNext()){
             ProxyReg reg = it.next();
@@ -1229,7 +1232,7 @@ abstract class AbstractLookupDiscoveryMa
      *               a member.
      * @param eventType The type of event.
      */
-    private void notifyListener(Map groupsMap, int eventType) {
+    private void notifyListener(Map<ServiceRegistrar, String[]> groupsMap, int eventType)
{
 	if(groupsMap.isEmpty()) return;
 	Iterator<DiscoveryListener> iter = listeners.iterator();
 	while(iter.hasNext()) {
@@ -1253,7 +1256,7 @@ abstract class AbstractLookupDiscoveryMa
      * @param eventType The type of the event.
      */
     private void notifyListener(DiscoveryListener l,
-                                Map groupsMap,
+                                Map<ServiceRegistrar, String[]> groupsMap,
                                 int eventType)
     {
         /* always send discovered and discarded events, not always changed */
@@ -1261,7 +1264,7 @@ abstract class AbstractLookupDiscoveryMa
             return;
         }
         DiscoveryEvent evt = new DiscoveryEvent(AbstractLookupDiscoveryManager.this,
-                                                deepCopy((HashMap)groupsMap) );
+                                                deepCopy(groupsMap) );
         switch(eventType) {
             case DISCOVERED:
                 l.discovered(evt);
@@ -1337,15 +1340,16 @@ abstract class AbstractLookupDiscoveryMa
      *  @return clone of the input map, and of each key-value pair contained
      *          in the input map
      */
-    private Map deepCopy(HashMap groupsMap) {
+    private Map<ServiceRegistrar, String[]> deepCopy(Map<ServiceRegistrar, String[]>
groupsMap) {
         /* clone the input HashMap */
-        HashMap newMap = (HashMap)(groupsMap.clone());
+        Map<ServiceRegistrar, String[]> newMap 
+                = new HashMap<ServiceRegistrar, String[]>(groupsMap);
         /* clone the values of each mapping in place */
-        Set eSet = newMap.entrySet();
-        for(Iterator itr = eSet.iterator(); itr.hasNext(); ) {
-            Map.Entry pair = (Map.Entry)itr.next();
+        Set<Map.Entry<ServiceRegistrar, String[]>> eSet = newMap.entrySet();
+        for(Iterator<Map.Entry<ServiceRegistrar, String[]>> itr = eSet.iterator();
itr.hasNext(); ) {
+            Map.Entry<ServiceRegistrar, String[]> pair = itr.next();
             /* only need to clone the value of the order pair */
-            pair.setValue( ((String[])pair.getValue()).clone() );
+            pair.setValue( pair.getValue().clone() );
         }
         return newMap;
     }//end deepCopy

Modified: river/jtsk/trunk/src/net/jini/discovery/AbstractLookupLocatorDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/AbstractLookupLocatorDiscovery.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/AbstractLookupLocatorDiscovery.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/AbstractLookupLocatorDiscovery.java Sun Dec 13
05:09:57 2015
@@ -377,13 +377,13 @@ abstract class AbstractLookupLocatorDisc
     /** Data structure containing task data processed by the Notifier Thread */
     private static class NotifyTask {
 	/** The listeners to notify */
-	public final List listeners;
+	public final List<DiscoveryListener> listeners;
 	/** Map of discovered registrars to groups in which each is a member */
-	public final Map groupsMap;
+	public final Map<ServiceRegistrar, String[]> groupsMap;
 	/** True if discarded, else discovered */
 	public final boolean discard;
-	public NotifyTask(List listeners,
-                          Map groupsMap,
+	public NotifyTask(List<DiscoveryListener> listeners,
+                          Map<ServiceRegistrar, String[]> groupsMap,
 			  boolean discard)
 	{
 	    this.listeners = listeners;
@@ -422,11 +422,11 @@ abstract class AbstractLookupLocatorDisc
                     return;
                 }
                 boolean firstListener = true;
-		for(Iterator iter = task.listeners.iterator();iter.hasNext();){
-		    DiscoveryListener l = (DiscoveryListener)iter.next();
+		for(Iterator<DiscoveryListener> iter = task.listeners.iterator();iter.hasNext();){
+		    DiscoveryListener l = iter.next();
 		    DiscoveryEvent e =
                         new DiscoveryEvent(AbstractLookupLocatorDiscovery.this,
-                                           deepCopy((HashMap)task.groupsMap) );
+                                           deepCopy(task.groupsMap) );
                     /* Log the event info about the lookup(s) */
                     if(firstListener && (logger.isLoggable(Level.FINEST)) ) {
                         String eType = (task.discard ? 
@@ -638,13 +638,14 @@ abstract class AbstractLookupLocatorDisc
             if(listeners.contains(l)) return; //already have this listener
             listeners.add(l); // Small window where it's possible to add duplicates.
         }
-        Map groupsMap = new HashMap(discoveredLocators.size());
+        Map<ServiceRegistrar, String[]> groupsMap 
+                = new HashMap<ServiceRegistrar, String[]>(discoveredLocators.size());
         Iterator<LocatorReg> iter = discoveredLocators.iterator();
         while (iter.hasNext()) {
             LocatorReg reg = iter.next();
             groupsMap.put(reg.getProxy(), reg.getMemberGroups());
         }//end loop
-        List list = new ArrayList(1);
+        List<DiscoveryListener> list = new ArrayList<DiscoveryListener>(1);
         list.add(l);
         if (!groupsMap.isEmpty()) addNotify(list, groupsMap, false);
     }//end addDiscoveryListener
@@ -1159,8 +1160,8 @@ abstract class AbstractLookupLocatorDisc
     /** Add a notification task to the pending queue, and start an instance of
      *  the Notifier thread if one isn't already running.
      */
-    private void addNotify(List notifies,
-                           Map groupsMap,
+    private void addNotify(List<DiscoveryListener> notifies,
+                           Map<ServiceRegistrar, String[]> groupsMap,
 			   boolean discard)
     {
         pendingNotifies.addLast(new NotifyTask(notifies,
@@ -1265,15 +1266,18 @@ abstract class AbstractLookupLocatorDisc
      *  @return clone of the input map, and of each key-value pair contained
      *          in the input map
      */
-    private Map deepCopy(HashMap groupsMap) {
+    private Map<ServiceRegistrar, String[]> deepCopy(Map<ServiceRegistrar, String[]>
groupsMap) {
         /* clone the input HashMap */
-        HashMap newMap = (HashMap)(groupsMap.clone());
+        Map<ServiceRegistrar, String[]> newMap 
+                = new HashMap<ServiceRegistrar, String[]>(groupsMap);
         /* clone the values of each mapping in place */
-        Set eSet = newMap.entrySet();
-        for(Iterator itr = eSet.iterator(); itr.hasNext(); ) {
-            Map.Entry pair = (Map.Entry)itr.next();
+        Set<Map.Entry<ServiceRegistrar, String[]>> eSet = newMap.entrySet();
+        for(Iterator<Map.Entry<ServiceRegistrar, String[]>> itr = eSet.iterator();
+                itr.hasNext(); ) 
+        {
+            Map.Entry<ServiceRegistrar, String[]> pair = itr.next();
             /* only need to clone the value of the order pair */
-            pair.setValue( ((String[])pair.getValue()).clone() );
+            pair.setValue( pair.getValue().clone() );
         }//end loop
         return newMap;
     }//end deepCopy

Modified: river/jtsk/trunk/src/net/jini/discovery/Constants.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/Constants.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/Constants.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/Constants.java Sun Dec 13 05:09:57 2015
@@ -39,6 +39,8 @@ public class Constants {
      * announcement protocol takes place.
      */
     private static InetAddress announcementAddress = null;
+    
+    private static final Object LOCK = new Object();
 
     /**
      * The port for both unicast and multicast boot requests.
@@ -60,9 +62,11 @@ public class Constants {
     public static final InetAddress getRequestAddress()
 	throws UnknownHostException
     {
-	if (requestAddress == null)
-	    requestAddress = InetAddress.getByName("224.0.1.85");
-	return requestAddress;
+        synchronized (LOCK){
+            if (requestAddress != null) return requestAddress;
+            requestAddress = InetAddress.getByName("224.0.1.85");
+            return requestAddress;
+        }
     }
   
 
@@ -76,8 +80,10 @@ public class Constants {
     public static final InetAddress getAnnouncementAddress()
 	throws UnknownHostException
     {
-	if (announcementAddress == null)
-	    announcementAddress = InetAddress.getByName("224.0.1.84");
-	return announcementAddress;
+        synchronized (LOCK){
+            if (announcementAddress != null) return announcementAddress;
+            announcementAddress = InetAddress.getByName("224.0.1.84");
+            return announcementAddress;
+        }
     }
 }

Modified: river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java Sun Dec 13 05:09:57 2015
@@ -19,6 +19,7 @@ package net.jini.discovery;
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.util.Collections;
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.Map;
@@ -55,7 +56,7 @@ public class DiscoveryEvent extends Even
      *
      * @serial
      */
-    private volatile Map groups;
+    private volatile Map<ServiceRegistrar, String[]> groups;
 
     /**
      * Construct a new <code>DiscoveryEvent</code> object, with the given
@@ -81,10 +82,10 @@ public class DiscoveryEvent extends Even
      *               event to the member groups in which each registrar is
      *               a member
      */
-    public DiscoveryEvent(Object source, Map groups) {
+    public DiscoveryEvent(Object source, Map<ServiceRegistrar, String[]> groups) {
 	super(source);
 	this.groups = groups;
-        this.regs   = (ServiceRegistrar[])(groups.keySet()).toArray
+        this.regs   = groups.keySet().toArray
                                        (new ServiceRegistrar[groups.size()]);
     }
 
@@ -116,14 +117,22 @@ public class DiscoveryEvent extends Even
      *          arrays containing the member groups corresponding to each
      *          registrar.
      */
-    public Map getGroups() {
-        return groups != null ? new HashMap(groups) : null;
+    public Map<ServiceRegistrar, String[]> getGroups() {
+        return groups != null ? new HashMap<ServiceRegistrar, String[]>(groups) : null;
     }
     
     @SuppressWarnings("unchecked")
     private void readObject(ObjectInputStream oin) throws IOException, ClassNotFoundException{
         oin.defaultReadObject();
         regs = regs.clone();
-        if (groups != null) groups = new HashMap(groups);
+        Map<ServiceRegistrar, String[]> groupClone;
+        Map<ServiceRegistrar, String[]> typeCheckedGroups;
+        if (groups != null) {
+            groupClone = new HashMap<ServiceRegistrar, String[]>(groups.size());
+            typeCheckedGroups = Collections.checkedMap(groupClone, ServiceRegistrar.class,
String[].class);
+            typeCheckedGroups.putAll(groups);
+            groups = groupClone;
+        }
+            
     }
 }

Modified: river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java Sun Dec 13 05:09:57 2015
@@ -646,7 +646,7 @@ import net.jini.core.constraint.MethodCo
  * @see DiscoveryEvent
  * @see DiscoveryPermission
  */
-public class LookupDiscovery extends AbstractLookupDiscovery 
+public final class LookupDiscovery extends AbstractLookupDiscovery 
                              implements DiscoveryManagement,
                                         DiscoveryGroupManagement
 {

Modified: river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java Sun Dec 13 05:09:57
2015
@@ -107,7 +107,7 @@ import net.jini.core.lookup.ServiceRegis
  * @see net.jini.discovery.DiscoveryLocatorManagement
  * 
  */
-public class LookupDiscoveryManager extends AbstractLookupDiscoveryManager 
+public final class LookupDiscoveryManager extends AbstractLookupDiscoveryManager 
                                     implements DiscoveryManagement,
                                                DiscoveryGroupManagement,
                                                DiscoveryLocatorManagement

Modified: river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java (original)
+++ river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java Sun Dec 13 05:09:57
2015
@@ -283,7 +283,7 @@ import org.apache.river.impl.thread.Name
  *
  * @see net.jini.core.discovery.LookupLocator
  */
-public class LookupLocatorDiscovery extends AbstractLookupLocatorDiscovery 
+public final class LookupLocatorDiscovery extends AbstractLookupLocatorDiscovery 
                                     implements DiscoveryManagement,
                                                DiscoveryLocatorManagement
 {

Modified: river/jtsk/trunk/src/net/jini/export/ServerContext.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/export/ServerContext.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/export/ServerContext.java (original)
+++ river/jtsk/trunk/src/net/jini/export/ServerContext.java Sun Dec 13 05:09:57 2015
@@ -23,6 +23,7 @@ import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 import net.jini.io.context.ClientHost;
 import net.jini.io.context.ClientSubject;
 import net.jini.security.Security;
@@ -46,24 +47,28 @@ import net.jini.security.Security;
 public final class ServerContext {
 
     private static final ThreadLocal state = new ThreadLocal();
-    private static ServerContext.Spi[] providers = null;
+    private static ServerContext.Spi[] providers = null; 
+    private static final Object LOCK = new Object();
 
-    private static ServerContext.Spi[] getProviders() {
-        if (providers == null) {
-            providers = (ServerContext.Spi[]) Security.doPrivileged(new PrivilegedAction()
{
+    private static Spi[] getProviders() {
+        synchronized (LOCK){
+            if (providers != null) return providers;
+            
+            providers = Security.doPrivileged(new PrivilegedAction<Spi[]>() {
 
-                public Object run() {
+                public Spi[] run() {
                     ClassLoader cl = Thread.currentThread().getContextClassLoader();
-                    ArrayList list = new ArrayList(1);
-                    Iterator i = Service.providers(ServerContext.Spi.class, cl);
+                    List<Spi> list = new ArrayList<Spi>(1);
+                    Iterator<Spi> i = Service.providers(Spi.class, cl);
                     while (i.hasNext()) {
                         list.add(i.next());
                     }
-                    return list.toArray(new ServerContext.Spi[list.size()]);
+                    return list.toArray(new Spi[list.size()]);
                 }
             });
+        
+            return providers;
         }
-        return providers;
     }
 
     /**
@@ -161,7 +166,7 @@ public final class ServerContext {
             throws ServerNotActiveException {
         Collection context = (Collection) state.get();
         if (context == null) {
-            for (int i = 0; i < getProviders().length; i++) {
+            for (int i = 0, l = getProviders().length; i < l; i++) {
                 if ((context = getProviders()[i].getServerContext()) != null) {
                     break;
                 }

Modified: river/jtsk/trunk/src/net/jini/lease/LeaseRenewalManager.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/lease/LeaseRenewalManager.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/lease/LeaseRenewalManager.java (original)
+++ river/jtsk/trunk/src/net/jini/lease/LeaseRenewalManager.java Sun Dec 13 05:09:57 2015
@@ -355,8 +355,7 @@ public class LeaseRenewalManager {
 	cancelMethod, cancelAllMethod, renewMethod, renewAllMethod
     };
 
-    /** Time window in which to look for batchable leases */
-    private long renewBatchTimeWindow = 1000 * 60 * 5;
+    private final long renewBatchTimeWindow;
 
     /** Task manager for queuing and renewing leases 
      *  NOTE: test failures occur with queue's that have capacity, 
@@ -371,7 +370,7 @@ public class LeaseRenewalManager {
     /**
      * The worst-case renewal round-trip-time
      */
-    private static long renewalRTT = 10 * 1000;
+    private final long renewalRTT ;
 
     /** 
      * Entries for leases that are not actively being renewed.
@@ -413,7 +412,7 @@ public class LeaseRenewalManager {
 
 	    if (e.renewalsDone() || e.endTime <= now) {
 		noRenewals = true;
-		Map lMap = leases.tailMap(new Entry(now));
+		Map lMap = leases.tailMap(new Entry(now, renewalRTT));
 		for (Iterator iter = lMap.values().iterator(); 
 		     iter.hasNext(); )
 		{
@@ -431,8 +430,7 @@ public class LeaseRenewalManager {
 		}
 	    } else {
 		noRenewals = false;
-		Map lMap = leases.tailMap(
-		    new Entry(e.renew + renewBatchTimeWindow));
+		Map lMap = leases.tailMap(new Entry(e.renew + renewBatchTimeWindow, renewalRTT));
 		for (Iterator iter = lMap.values().iterator(); 
 		     iter.hasNext(); )
 		{
@@ -510,6 +508,7 @@ public class LeaseRenewalManager {
 	public final LeaseListener listener;
 	/** Current actual expiration */
 	public long endTime;
+        private final long renewalRTT;
 
 	/** 
 	 * The next time we have to do something with this lease.
@@ -523,25 +522,24 @@ public class LeaseRenewalManager {
 	/** Renewal exception, or null */
 	public Throwable ex = null;
 
-	public Entry(Lease lease,
-		     long expiration,
-		     long renewDuration,
-		     LeaseListener listener)
+	public Entry(Lease lease, long expiration, long renewDuration, long renewalRTT, LeaseListener
listener)
 	{
 	    this.endTime = lease.getExpiration();
 	    this.lease = lease;
 	    this.expiration = expiration;
 	    this.renewDuration = renewDuration;
 	    this.listener = listener;
+            this.renewalRTT = renewalRTT;
 	    id = cnt++;
 	}
 
 	/** Create a fake entry for tailMap */
-	public Entry(long renew) {
+	public Entry(long renew, long renewalRTT) {
 	    this.renew = renew;
 	    id = Long.MAX_VALUE;
 	    lease = null;
 	    listener = null;
+            this.renewalRTT = renewalRTT;
 	}
 
 	/**
@@ -713,6 +711,8 @@ public class LeaseRenewalManager {
      * that initially manages no leases.
      */
     public LeaseRenewalManager() {
+        this.renewBatchTimeWindow = 1000 * 60 * 5;
+        this.renewalRTT = 10 * 1000;
         leaseRenewalExecutor = 
             new ThreadPoolExecutor(
                     1,  /* min threads */
@@ -724,6 +724,43 @@ public class LeaseRenewalManager {
                     new CallerRunsPolicy()
             );
     }
+    
+    private static Init init(Configuration config) throws ConfigurationException{
+        return new Init(config);
+    }
+    
+    private static class Init {
+        long renewBatchTimeWindow = 1000 * 60 * 5 ;
+        long renewalRTT = 10 * 1000;
+        ExecutorService leaseRenewalExecutor;
+        
+        Init(Configuration config) throws ConfigurationException{
+            if (config == null) {
+	    throw new NullPointerException("config is null");
+            }
+            renewBatchTimeWindow = Config.getLongEntry(
+                config, LRM, "renewBatchTimeWindow",
+                renewBatchTimeWindow, 0, Long.MAX_VALUE);
+            renewalRTT = Config.getLongEntry(
+                config, LRM, "roundTripTime",
+                renewalRTT, 1, Long.MAX_VALUE);
+            leaseRenewalExecutor = Config.getNonNullEntry(
+                config, 
+                LRM, 
+                "executorService", 
+                ExecutorService.class,
+                new ThreadPoolExecutor(
+                        1,  /* Min Threads */
+                        11, /* Max Threads */
+                        15,
+                        TimeUnit.SECONDS, 
+                        new SynchronousQueue<Runnable>(), /* No capacity */
+                        new NamedThreadFactory("LeaseRenewalManager",false),
+                        new CallerRunsPolicy()
+                ) 
+            );
+        }
+    }
 
     /**
      * Constructs an instance of this class that initially manages no leases
@@ -739,30 +776,13 @@ public class LeaseRenewalManager {
     public LeaseRenewalManager(Configuration config)
 	throws ConfigurationException
     {
-	if (config == null) {
-	    throw new NullPointerException("config is null");
-	}
-	renewBatchTimeWindow = Config.getLongEntry(
-	    config, LRM, "renewBatchTimeWindow",
-	    renewBatchTimeWindow, 0, Long.MAX_VALUE);
-	renewalRTT = Config.getLongEntry(
-	    config, LRM, "roundTripTime",
-	    renewalRTT, 1, Long.MAX_VALUE);
-	leaseRenewalExecutor = Config.getNonNullEntry(
-            config, 
-            LRM, 
-            "executorService", 
-            ExecutorService.class,
-            new ThreadPoolExecutor(
-                    1,  /* Min Threads */
-                    11, /* Max Threads */
-                    15,
-                    TimeUnit.SECONDS, 
-                    new SynchronousQueue<Runnable>(), /* No capacity */
-                    new NamedThreadFactory("LeaseRenewalManager",false),
-                    new CallerRunsPolicy()
-            ) 
-        );
+	this(init(config));
+    }
+    
+    private LeaseRenewalManager(Init init){
+        this.renewBatchTimeWindow = init.renewBatchTimeWindow;
+        this.renewalRTT = init.renewalRTT;
+        this.leaseRenewalExecutor = init.leaseRenewalExecutor;
     }
 
     /**
@@ -790,6 +810,8 @@ public class LeaseRenewalManager {
 			       long desiredExpiration,
 			       LeaseListener listener)
     {
+        this.renewBatchTimeWindow = 1000 * 60 * 5;
+        this.renewalRTT = 10 * 1000;
         leaseRenewalExecutor = new ThreadPoolExecutor(
                 1,  /* Min Threads */
                 11, /* Max Threads */
@@ -1093,7 +1115,7 @@ public class LeaseRenewalManager {
 	Entry e = findEntryDo(lease);
 	if (e != null && !removeLeaseInRenew(e))
 	    leases.remove(e);
-	insertEntry(new Entry(lease, desiredExpiration, renewDuration,
+	insertEntry(new Entry(lease, desiredExpiration, renewDuration, renewalRTT,
 			      listener),
 		    now);
 	calcActualRenews(now);

Modified: river/jtsk/trunk/src/net/jini/lookup/JoinManager.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/lookup/JoinManager.java (original)
+++ river/jtsk/trunk/src/net/jini/lookup/JoinManager.java Sun Dec 13 05:09:57 2015
@@ -46,6 +46,7 @@ import net.jini.core.lookup.ServiceRegis
 import net.jini.core.lookup.ServiceRegistration;
 
 import java.io.IOException;
+import java.rmi.RemoteException;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -2432,7 +2433,8 @@ public class JoinManager {
         while (iter.hasNext()) {
             try {
                 leaseRenewalMgr.cancel(iter.next().serviceLease );
-            } catch (Exception e){}
+            } catch (UnknownLeaseException e){
+            } catch (RemoteException e) {}
         }//end loop
         leaseRenewalMgr.close();
         joinSet.clear();

Modified: river/jtsk/trunk/src/org/apache/river/jeri/internal/http/Header.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/org/apache/river/jeri/internal/http/Header.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/org/apache/river/jeri/internal/http/Header.java (original)
+++ river/jtsk/trunk/src/org/apache/river/jeri/internal/http/Header.java Sun Dec 13 05:09:57
2015
@@ -37,10 +37,10 @@ import java.util.TimeZone;
  */
 class Header {
     
-    private static final SimpleDateFormat dateFormat;
+    private static final SimpleDateFormat DATE_FORMAT;
     static {
-	dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'");
-	dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+	DATE_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'");
+	DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
     }
     
     private Map fields = new HashMap(5);
@@ -166,7 +166,9 @@ class Header {
      * Returns formatted date string for given time.
      */
     static String getDateString(long time) {
-	return dateFormat.format(new Date(time));
+        synchronized (DATE_FORMAT){
+            return DATE_FORMAT.format(new Date(time));
+        }
     }
 
     private static boolean isSpaceOrTab(char c) {

Modified: river/jtsk/trunk/src/org/apache/river/mahalo/log/MultiLogManager.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/org/apache/river/mahalo/log/MultiLogManager.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/org/apache/river/mahalo/log/MultiLogManager.java (original)
+++ river/jtsk/trunk/src/org/apache/river/mahalo/log/MultiLogManager.java Sun Dec 13 05:09:57
2015
@@ -267,7 +267,7 @@ public class MultiLogManager
 	    tmpfile = new File(directory);
 	    filenames = tmpfile.list(filter);
 
-	    if (filenames.length == 0)
+	    if (filenames == null || filenames.length == 0)
 	      return;
 
             String logName;

Modified: river/jtsk/trunk/src/org/apache/river/mahalo/log/SimpleLogFile.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/org/apache/river/mahalo/log/SimpleLogFile.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/org/apache/river/mahalo/log/SimpleLogFile.java (original)
+++ river/jtsk/trunk/src/org/apache/river/mahalo/log/SimpleLogFile.java Sun Dec 13 05:09:57
2015
@@ -57,12 +57,12 @@ public class SimpleLogFile implements Lo
      */
     private /*final*/ FileOutputStream outfile;
     /** (Relative) File name of the log file */
-    private /*final*/ String name;
+    private final String name;
     /** 
      * Reference to <code>LogRemovalManager</code>, which is called
      * to remove this log from the managed set of logs.
      */
-    private /*final*/ LogRemovalManager logMgr;
+    private final LogRemovalManager logMgr;
     /** 
      * Flag that indicates validity of this log. Set to false
      * by call to <code>invalidate()</code>.
@@ -167,7 +167,7 @@ public class SimpleLogFile implements Lo
      * @see org.apache.river.mahalo.log.MultiLogManager.LogRemovalManager
      */
     public SimpleLogFile(String name, LogRemovalManager logMgr) {
-	init(name, 0, logMgr);
+	this(name, 0, logMgr);
 	readonly = true;
     }
 
@@ -188,14 +188,7 @@ public class SimpleLogFile implements Lo
      * @see org.apache.river.mahalo.log.MultiLogManager.LogRemovalManager
      */
     public SimpleLogFile(String name, long cookie, LogRemovalManager logMgr) {
-	init(name, cookie, logMgr);
-    }
-
-    /*
-     * Utility method that contains code common to all constructors 
-     */
-    private void init(String name, long cookie, LogRemovalManager logMgr) {
-        if (operationsLogger.isLoggable(Level.FINER)) {
+	if (operationsLogger.isLoggable(Level.FINER)) {
             operationsLogger.entering(SimpleLogFile.class.getName(), 
 	        "init", new Object[] {name, Long.valueOf(cookie), logMgr});
 	}
@@ -222,7 +215,7 @@ public class SimpleLogFile implements Lo
      *
      * @see org.apache.river.mahalo.log.Log
      */
-    public long cookie() {
+    public synchronized long cookie() {
 	return cookie;
     }
 

Modified: river/jtsk/trunk/src/org/apache/river/norm/LeaseSet.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/org/apache/river/norm/LeaseSet.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/org/apache/river/norm/LeaseSet.java (original)
+++ river/jtsk/trunk/src/org/apache/river/norm/LeaseSet.java Sun Dec 13 05:09:57 2015
@@ -136,6 +136,7 @@ class LeaseSet implements Serializable,
 	this.ID = ID;
 
 	// For completeness
+        expiration = 0;
 	expiration2 = new ExpirationTime(expiration);
 	leaseTable = new LeaseTable();
 

Modified: river/jtsk/trunk/src/org/apache/river/reggie/RegistrarImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/org/apache/river/reggie/RegistrarImpl.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/org/apache/river/reggie/RegistrarImpl.java (original)
+++ river/jtsk/trunk/src/org/apache/river/reggie/RegistrarImpl.java Sun Dec 13 05:09:57 2015
@@ -329,7 +329,7 @@ class RegistrarImpl implements Registrar
     private final Thread snapshotter;
 
     /** Concurrent object to control read and write access */
-    private final ReadersWriter concurrentObj = new ReadersWriter();
+    private final ReadersWriter concurrentObj;
     /** Object for synchronizing with the service expire thread */
     private final Condition serviceNotifier;
     /** Object for synchronizing with the event expire thread */
@@ -486,6 +486,7 @@ class RegistrarImpl implements Registrar
     }
     
      private RegistrarImpl(Initializer init){
+        this.concurrentObj = new ReadersWriter();
         this.snapshotNotifier = concurrentObj.newCondition();
         this.eventNotifier = concurrentObj.newCondition();
         this.serviceNotifier = concurrentObj.newCondition();

Modified: river/jtsk/trunk/src/org/apache/river/start/ProxyVerifier.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/org/apache/river/start/ProxyVerifier.java?rev=1719763&r1=1719762&r2=1719763&view=diff
==============================================================================
--- river/jtsk/trunk/src/org/apache/river/start/ProxyVerifier.java (original)
+++ river/jtsk/trunk/src/org/apache/river/start/ProxyVerifier.java Sun Dec 13 05:09:57 2015
@@ -32,7 +32,7 @@ final class ProxyVerifier implements Tru
     private static final long serialVersionUID = 1L;
 
     /** Logger and configuration component name for SharedGroup */
-    protected static final String START_PROXY = "org.apache.river.start.proxy";
+    private static final String START_PROXY = "org.apache.river.start.proxy";
 
     /** Logger for logging information about this instance */
     private static final Logger logger = Logger.getLogger(START_PROXY);




Mime
View raw message