Modified: river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarEvent.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarEvent.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarEvent.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarEvent.java Sun Jul 5 11:41:39 2020 @@ -1,118 +1,118 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.reggie; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.rmi.MarshalledObject; -import net.jini.core.lookup.ServiceEvent; -import net.jini.core.lookup.ServiceID; -import net.jini.core.lookup.ServiceItem; - -/** - * Concrete implementation class for abstract ServiceEvent. - * - * @author Sun Microsystems, Inc. - * - */ -class RegistrarEvent extends ServiceEvent { - - private static final long serialVersionUID = 2L; - - /** - * The new state of the serviceItem, or null if the serviceItem has been - * deleted from the lookup service. This is either a ServiceItem - * or an Item (to be converted to a ServiceItem when unmarshalled). - * - * @serial - */ - private volatile Object serviceItem; - /** - * The service ID of the serviceItem that triggered the event. This field is used - * instead of the inherited serviceID field (which is set to null) and is - * written directly as a 128-bit value in order to avoid potential codebase - * annotation loss (see bug 4745728). - */ - private transient ServiceID servID; - - /** - * Simple constructor. - * - * @param source the ServiceRegistrar that generated the event - * @param eventID the registration eventID - * @param seqNo the sequence number of this event - * @param handback the client handback - * @param serviceID the serviceID of the serviceItem that triggered the event - * @param transition the transition that triggered the event - * @param item the new state of the serviceItem, or null if deleted - */ - public RegistrarEvent(Object source, - long eventID, - long seqNo, - MarshalledObject handback, - ServiceID serviceID, - int transition, - Item item) - { - super(source, eventID, seqNo, handback, null, transition); - this.serviceItem = item; - servID = serviceID; - } - - /** - * Returns the new state of the serviceItem, or null if the serviceItem was deleted - * from the lookup service. - */ - public ServiceItem getServiceItem() { - if (serviceItem instanceof ServiceItem){ - return ((ServiceItem) serviceItem).clone(); - } - return (ServiceItem)serviceItem; - } - - // javadoc inherited from ServiceEvent - public ServiceID getServiceID() { - return servID; - } - - /** - * Writes the default serializable field value for this instance, followed - * by the serviceItem's service ID encoded as specified by the - * ServiceID.writeBytes method. - */ - private void writeObject(ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - servID.writeBytes(out); - } - - /** - * Reads the default serializable field value for this instance, followed - * by the serviceItem's service ID encoded as specified by the - * ServiceID.writeBytes method. If the value of the serviceItem field is an Item - * instance, converts it to a ServiceItem. - */ - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException - { - in.defaultReadObject(); - servID = new ServiceID(in); - if (serviceItem instanceof Item) - serviceItem = ((Item)serviceItem).get(); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.reggie.proxy; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.rmi.MarshalledObject; +import net.jini.core.lookup.ServiceEvent; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceItem; + +/** + * Concrete implementation class for abstract ServiceEvent. + * + * @author Sun Microsystems, Inc. + * + */ +public class RegistrarEvent extends ServiceEvent { + + private static final long serialVersionUID = 2L; + + /** + * The new state of the serviceItem, or null if the serviceItem has been + * deleted from the lookup service. This is either a ServiceItem + * or an Item (to be converted to a ServiceItem when unmarshalled). + * + * @serial + */ + private volatile Object serviceItem; + /** + * The service ID of the serviceItem that triggered the event. This field is used + * instead of the inherited serviceID field (which is set to null) and is + * written directly as a 128-bit value in order to avoid potential codebase + * annotation loss (see bug 4745728). + */ + private transient ServiceID servID; + + /** + * Simple constructor. + * + * @param source the ServiceRegistrar that generated the event + * @param eventID the registration eventID + * @param seqNo the sequence number of this event + * @param handback the client handback + * @param serviceID the serviceID of the serviceItem that triggered the event + * @param transition the transition that triggered the event + * @param item the new state of the serviceItem, or null if deleted + */ + public RegistrarEvent(Object source, + long eventID, + long seqNo, + MarshalledObject handback, + ServiceID serviceID, + int transition, + Item item) + { + super(source, eventID, seqNo, handback, null, transition); + this.serviceItem = item; + servID = serviceID; + } + + /** + * Returns the new state of the serviceItem, or null if the serviceItem was deleted + * from the lookup service. + */ + public ServiceItem getServiceItem() { + if (serviceItem instanceof ServiceItem){ + return ((ServiceItem) serviceItem).clone(); + } + return (ServiceItem)serviceItem; + } + + // javadoc inherited from ServiceEvent + public ServiceID getServiceID() { + return servID; + } + + /** + * Writes the default serializable field value for this instance, followed + * by the serviceItem's service ID encoded as specified by the + * ServiceID.writeBytes method. + */ + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + servID.writeBytes(out); + } + + /** + * Reads the default serializable field value for this instance, followed + * by the serviceItem's service ID encoded as specified by the + * ServiceID.writeBytes method. If the value of the serviceItem field is an Item + * instance, converts it to a ServiceItem. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + servID = new ServiceID(in); + if (serviceItem instanceof Item) + serviceItem = ((Item)serviceItem).get(); + } +}
Modified: river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarLease.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarLease.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarLease.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarLease.java Sun Jul 5 11:41:39 2020 @@ -1,175 +1,175 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.reggie; - -import org.apache.river.lease.AbstractLease; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamException; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseMap; -import net.jini.core.lookup.ServiceID; -import net.jini.id.ReferentUuid; -import net.jini.id.ReferentUuids; -import net.jini.id.Uuid; -import org.apache.river.lease.ID; - -/** - * The base class for lease proxies. - * - * @author Sun Microsystems, Inc. - * - */ -abstract class RegistrarLease extends AbstractLease implements ReferentUuid, ID<Uuid> { - - private static final long serialVersionUID = 2L; - - /** - * The registrar. - * - * @serial - */ - final Registrar server; - /** - * The registrar's service ID. - */ - transient ServiceID registrarID; - /** - * The internal lease id. - * - * @serial - */ - final Uuid leaseID; - - /** Simple constructor. */ - RegistrarLease(Registrar server, - ServiceID registrarID, - Uuid leaseID, - long expiration) - { - super(expiration); - this.server = server; - this.registrarID = registrarID; - this.leaseID = leaseID; - } - - /** Creates a lease map. */ - public LeaseMap<? extends Lease,Long> createLeaseMap(long duration) { - return new RegistrarLeaseMap(this, duration); - } - - /** - * Two leases can be batched if they are both RegistrarLeases and - * have the same server. - */ - public boolean canBatch(Lease lease) { - return (lease instanceof RegistrarLease && - registrarID.equals(((RegistrarLease) lease).registrarID)); - } - - /** Returns the lease Uuid. */ - public Uuid getReferentUuid() { - return leaseID; - } - - /** Returns the lease Uuid's hash code. */ - public int hashCode() { - return leaseID.hashCode(); - } - - /** Returns true if lease Uuids match, false otherwise. */ - public boolean equals(Object obj) { - return ReferentUuids.compare(this, obj); - } - - /** - * Returns a string created from the proxy class name, the registrar's - * service ID, the id of the lessee or event (depending on the subclass), - * and the result of the underlying server proxy's toString method. - * - * @return String - */ - public String toString() { - String className = getClass().getName(); - return className + "[registrar=" + registrarID + " " + server - + ", lease=" + leaseID + ", " + getLeaseType() + "=" + getRegID() - + "]"; - } - - - /** Returns the registrar. */ - Registrar getRegistrar() { - return server; - } - - /** Returns the registrar's service ID. */ - ServiceID getRegistrarID() { - return registrarID; - } - - public Uuid identity(){ - return leaseID; - } - - /** Returns the service ID, or the event ID as a Long. */ - abstract Object getRegID(); - - /** Returns the type of the lease. */ - abstract String getLeaseType(); - - /** - * Writes the default serializable field values for this instance, followed - * by the registrar's service ID encoded as specified by the - * ServiceID.writeBytes method. - */ - private void writeObject(ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - registrarID.writeBytes(out); - } - - /** - * Reads the default serializable field values for this instance, followed - * by the registrar's service ID encoded as specified by the - * ServiceID.writeBytes method. Verifies that the deserialized field - * values are non-null. - */ - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException - { - in.defaultReadObject(); - registrarID = new ServiceID(in); - if (server == null) { - throw new InvalidObjectException("null server"); - } else if (leaseID == null) { - throw new InvalidObjectException("null leaseID"); - } - } - - /** - * Throws InvalidObjectException, since data for this class is required. - */ - private void readObjectNoData() throws ObjectStreamException { - throw new InvalidObjectException("no data"); - } - - void setExpiration(long expiration) { - this.expiration = expiration; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.reggie.proxy; + +import org.apache.river.lease.AbstractLease; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import net.jini.core.lease.Lease; +import net.jini.core.lease.LeaseMap; +import net.jini.core.lookup.ServiceID; +import net.jini.id.ReferentUuid; +import net.jini.id.ReferentUuids; +import net.jini.id.Uuid; +import org.apache.river.lease.ID; + +/** + * The base class for lease proxies. + * + * @author Sun Microsystems, Inc. + * + */ +abstract class RegistrarLease extends AbstractLease implements ReferentUuid, ID<Uuid> { + + private static final long serialVersionUID = 2L; + + /** + * The registrar. + * + * @serial + */ + final Registrar server; + /** + * The registrar's service ID. + */ + transient ServiceID registrarID; + /** + * The internal lease id. + * + * @serial + */ + final Uuid leaseID; + + /** Simple constructor. */ + RegistrarLease(Registrar server, + ServiceID registrarID, + Uuid leaseID, + long expiration) + { + super(expiration); + this.server = server; + this.registrarID = registrarID; + this.leaseID = leaseID; + } + + /** Creates a lease map. */ + public LeaseMap<? extends Lease,Long> createLeaseMap(long duration) { + return new RegistrarLeaseMap(this, duration); + } + + /** + * Two leases can be batched if they are both RegistrarLeases and + * have the same server. + */ + public boolean canBatch(Lease lease) { + return (lease instanceof RegistrarLease && + registrarID.equals(((RegistrarLease) lease).registrarID)); + } + + /** Returns the lease Uuid. */ + public Uuid getReferentUuid() { + return leaseID; + } + + /** Returns the lease Uuid's hash code. */ + public int hashCode() { + return leaseID.hashCode(); + } + + /** Returns true if lease Uuids match, false otherwise. */ + public boolean equals(Object obj) { + return ReferentUuids.compare(this, obj); + } + + /** + * Returns a string created from the proxy class name, the registrar's + * service ID, the id of the lessee or event (depending on the subclass), + * and the result of the underlying server proxy's toString method. + * + * @return String + */ + public String toString() { + String className = getClass().getName(); + return className + "[registrar=" + registrarID + " " + server + + ", lease=" + leaseID + ", " + getLeaseType() + "=" + getRegID() + + "]"; + } + + + /** Returns the registrar. */ + Registrar getRegistrar() { + return server; + } + + /** Returns the registrar's service ID. */ + ServiceID getRegistrarID() { + return registrarID; + } + + public Uuid identity(){ + return leaseID; + } + + /** Returns the service ID, or the event ID as a Long. */ + abstract Object getRegID(); + + /** Returns the type of the lease. */ + abstract String getLeaseType(); + + /** + * Writes the default serializable field values for this instance, followed + * by the registrar's service ID encoded as specified by the + * ServiceID.writeBytes method. + */ + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + registrarID.writeBytes(out); + } + + /** + * Reads the default serializable field values for this instance, followed + * by the registrar's service ID encoded as specified by the + * ServiceID.writeBytes method. Verifies that the deserialized field + * values are non-null. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + registrarID = new ServiceID(in); + if (server == null) { + throw new InvalidObjectException("null server"); + } else if (leaseID == null) { + throw new InvalidObjectException("null leaseID"); + } + } + + /** + * Throws InvalidObjectException, since data for this class is required. + */ + private void readObjectNoData() throws ObjectStreamException { + throw new InvalidObjectException("no data"); + } + + void setExpiration(long expiration) { + this.expiration = expiration; + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarLeaseMap.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarLeaseMap.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarLeaseMap.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarLeaseMap.java Sun Jul 5 11:41:39 2020 @@ -1,155 +1,155 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.reggie; - -import java.rmi.RemoteException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseMapException; -import net.jini.core.lookup.ServiceID; -import net.jini.id.Uuid; -import org.apache.river.lease.AbstractIDLeaseMap; - -/** - * The LeaseMap implementation class for registrar leases. Clients only see - * instances via the LeaseMap interface. - * - * @author Sun Microsystems, Inc. - * - */ -class RegistrarLeaseMap extends AbstractIDLeaseMap<RegistrarLease> { - - private static final long serialVersionUID = 2L; - - /** - * The registrar. - * - * @serial - */ - final Registrar server; - /** - * The registrar's service ID. - * - * @serial - */ - final ServiceID registrarID; - - /** Simple constructor */ - RegistrarLeaseMap(RegistrarLease lease, long duration) { - this(lease.getRegistrar(), lease, duration); - } - - /** Constructor used by ConstrainableRegistrarLeaseMap */ - RegistrarLeaseMap(Registrar server, RegistrarLease lease, long duration) { - super(); - this.server = server; - registrarID = lease.getRegistrarID(); - put(lease, Long.valueOf(duration)); - } - - /** Any RegistrarLease from the same server can be in the map */ - public boolean canContainKey(Object key) { - return (key instanceof RegistrarLease && - registrarID.equals(((RegistrarLease) key).getRegistrarID())); - } - - // This method's javadoc is inherited from an interface of this class - public void renewAll() throws LeaseMapException, RemoteException { - if (isEmpty()) return; - List<RegistrarLease> leases = new LinkedList<RegistrarLease>(); - List<Object> regIDS = new LinkedList<Object>(); - List<Uuid> leaseIDS = new LinkedList<Uuid>(); - List<Long> dur = new LinkedList<Long>(); - - Iterator<Map.Entry<RegistrarLease,Long>> itera = entrySet().iterator(); - while ( itera.hasNext()) { - Map.Entry<RegistrarLease,Long> e = itera.next(); - RegistrarLease lease = e.getKey(); - leases.add(lease); - regIDS.add(lease.getRegID()); - leaseIDS.add(lease.getReferentUuid()); - dur.add(e.getValue()); - } - Object[] regIDs = regIDS.toArray(new Object[regIDS.size()]); - Uuid[] leaseIDs = leaseIDS.toArray(new Uuid [leaseIDS.size()]); - long[] durations = new long[dur.size()]; - Iterator<Long> it = dur.iterator(); - int i = 0; - while (it.hasNext()){ - durations [i] = it.next(); - i++; - } - - //TODO finish below, watch out for results. - RenewResults results = server.renewLeases(regIDs, leaseIDs, durations); - long now = System.currentTimeMillis(); - Map<Lease,Exception> emap = (results.exceptions != null) ? - new HashMap<Lease,Exception>(2 * results.exceptions.length + 1) : null; - i = 0; - int j = 0; - for (Iterator<RegistrarLease> iter = leases.iterator(); iter.hasNext(); i++) { - RegistrarLease e = iter.next(); - long duration = results.durations[i]; - if (duration >= 0) { - e.setExpiration(duration + now); - } else { - emap.put(e, results.exceptions[j++]); - remove(e); - } - } - if (emap != null) - throw new LeaseMapException("lease renewal failures", emap); - } - - // This method's javadoc is inherited from an interface of this class - @SuppressWarnings("unchecked") - public void cancelAll() throws LeaseMapException, RemoteException { - // finish by copying above. - if (isEmpty()) return; - List<RegistrarLease> leases = new LinkedList<RegistrarLease>(); - List regIDs = new LinkedList(); - List<Uuid> leaseIDs = new LinkedList<Uuid>(); - int i = 0; - for (Iterator<RegistrarLease> iter = keySet().iterator(); iter.hasNext(); i++) { - RegistrarLease ls = iter.next(); - leases.add(ls); - regIDs.add(ls.getRegID()); - leaseIDs.add(ls.getReferentUuid()); - } - Exception[] exceptions = server.cancelLeases( - regIDs.toArray(), - leaseIDs.toArray(new Uuid[leaseIDs.size()]) - ); - if (exceptions == null) return; - i = 0; - Map<Lease,Exception> emap = new HashMap<Lease,Exception>(exceptions.length); - for (Iterator<RegistrarLease> iter = leases.iterator(); iter.hasNext(); i++) { - Lease ls = (Lease)iter.next(); - Exception ex = exceptions[i]; - if (ex != null) { - emap.put(ls, ex); - remove(ls); - } - } - throw new LeaseMapException("lease cancellation failures", emap); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.reggie.proxy; + +import java.rmi.RemoteException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import net.jini.core.lease.Lease; +import net.jini.core.lease.LeaseMapException; +import net.jini.core.lookup.ServiceID; +import net.jini.id.Uuid; +import org.apache.river.lease.AbstractIDLeaseMap; + +/** + * The LeaseMap implementation class for registrar leases. Clients only see + * instances via the LeaseMap interface. + * + * @author Sun Microsystems, Inc. + * + */ +class RegistrarLeaseMap extends AbstractIDLeaseMap<RegistrarLease> { + + private static final long serialVersionUID = 2L; + + /** + * The registrar. + * + * @serial + */ + final Registrar server; + /** + * The registrar's service ID. + * + * @serial + */ + final ServiceID registrarID; + + /** Simple constructor */ + RegistrarLeaseMap(RegistrarLease lease, long duration) { + this(lease.getRegistrar(), lease, duration); + } + + /** Constructor used by ConstrainableRegistrarLeaseMap */ + RegistrarLeaseMap(Registrar server, RegistrarLease lease, long duration) { + super(); + this.server = server; + registrarID = lease.getRegistrarID(); + put(lease, Long.valueOf(duration)); + } + + /** Any RegistrarLease from the same server can be in the map */ + public boolean canContainKey(Object key) { + return (key instanceof RegistrarLease && + registrarID.equals(((RegistrarLease) key).getRegistrarID())); + } + + // This method's javadoc is inherited from an interface of this class + public void renewAll() throws LeaseMapException, RemoteException { + if (isEmpty()) return; + List<RegistrarLease> leases = new LinkedList<RegistrarLease>(); + List<Object> regIDS = new LinkedList<Object>(); + List<Uuid> leaseIDS = new LinkedList<Uuid>(); + List<Long> dur = new LinkedList<Long>(); + + Iterator<Map.Entry<RegistrarLease,Long>> itera = entrySet().iterator(); + while ( itera.hasNext()) { + Map.Entry<RegistrarLease,Long> e = itera.next(); + RegistrarLease lease = e.getKey(); + leases.add(lease); + regIDS.add(lease.getRegID()); + leaseIDS.add(lease.getReferentUuid()); + dur.add(e.getValue()); + } + Object[] regIDs = regIDS.toArray(new Object[regIDS.size()]); + Uuid[] leaseIDs = leaseIDS.toArray(new Uuid [leaseIDS.size()]); + long[] durations = new long[dur.size()]; + Iterator<Long> it = dur.iterator(); + int i = 0; + while (it.hasNext()){ + durations [i] = it.next(); + i++; + } + + //TODO finish below, watch out for results. + RenewResults results = server.renewLeases(regIDs, leaseIDs, durations); + long now = System.currentTimeMillis(); + Map<Lease,Exception> emap = (results.exceptions != null) ? + new HashMap<Lease,Exception>(2 * results.exceptions.length + 1) : null; + i = 0; + int j = 0; + for (Iterator<RegistrarLease> iter = leases.iterator(); iter.hasNext(); i++) { + RegistrarLease e = iter.next(); + long duration = results.durations[i]; + if (duration >= 0) { + e.setExpiration(duration + now); + } else { + emap.put(e, results.exceptions[j++]); + remove(e); + } + } + if (emap != null) + throw new LeaseMapException("lease renewal failures", emap); + } + + // This method's javadoc is inherited from an interface of this class + @SuppressWarnings("unchecked") + public void cancelAll() throws LeaseMapException, RemoteException { + // finish by copying above. + if (isEmpty()) return; + List<RegistrarLease> leases = new LinkedList<RegistrarLease>(); + List regIDs = new LinkedList(); + List<Uuid> leaseIDs = new LinkedList<Uuid>(); + int i = 0; + for (Iterator<RegistrarLease> iter = keySet().iterator(); iter.hasNext(); i++) { + RegistrarLease ls = iter.next(); + leases.add(ls); + regIDs.add(ls.getRegID()); + leaseIDs.add(ls.getReferentUuid()); + } + Exception[] exceptions = server.cancelLeases( + regIDs.toArray(), + leaseIDs.toArray(new Uuid[leaseIDs.size()]) + ); + if (exceptions == null) return; + i = 0; + Map<Lease,Exception> emap = new HashMap<Lease,Exception>(exceptions.length); + for (Iterator<RegistrarLease> iter = leases.iterator(); iter.hasNext(); i++) { + Lease ls = (Lease)iter.next(); + Exception ex = exceptions[i]; + if (ex != null) { + emap.put(ls, ex); + remove(ls); + } + } + throw new LeaseMapException("lease cancellation failures", emap); + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarPermission.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarPermission.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarPermission.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarPermission.java Sun Jul 5 11:41:39 2020 @@ -1,59 +1,59 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.reggie; - -import net.jini.jeri.BasicInvocationDispatcher; -import net.jini.jeri.BasicJeriExporter; -import net.jini.security.AccessPermission; - -/** - * Permission that can be used to express the access control policy for an - * instance of the Reggie lookup service exported with a {@link - * BasicJeriExporter}. This class can be specified to {@link - * BasicInvocationDispatcher}, which will then perform permission checks for - * incoming remote calls using <code>RegistrarPermission</code> instances. - * <p> - * An instance contains a name (also referred to as a "target name") but no - * actions list; you either have the named permission or you don't. The - * convention is that the target name is the fully qualified name of the remote - * method being invoked. Wildcard matches are supported using the syntax - * specified by {@link AccessPermission}. - * <p> - * The possible target names for use with a Reggie server are specified in the - * package documentation for {@link org.apache.river.reggie}. - * - * @author Sun Microsystems, Inc. - * @since 2.0 - */ -public class RegistrarPermission extends AccessPermission { - - private static final long serialVersionUID = 2L; - - /** - * Creates an instance with the specified target name. - * - * @param name the target name - * @throws NullPointerException if the target name is <code>null</code> - * @throws IllegalArgumentException if the target name does not match - * the syntax specified in the comments at the beginning of the {@link - * AccessPermission} class - */ - public RegistrarPermission(String name) { - super(name); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.reggie.proxy; + +import net.jini.jeri.BasicInvocationDispatcher; +import net.jini.jeri.BasicJeriExporter; +import net.jini.security.AccessPermission; + +/** + * Permission that can be used to express the access control policy for an + * instance of the Reggie lookup service exported with a {@link + * BasicJeriExporter}. This class can be specified to {@link + * BasicInvocationDispatcher}, which will then perform permission checks for + * incoming remote calls using <code>RegistrarPermission</code> instances. + * <p> + * An instance contains a name (also referred to as a "target name") but no + * actions list; you either have the named permission or you don't. The + * convention is that the target name is the fully qualified name of the remote + * method being invoked. Wildcard matches are supported using the syntax + * specified by {@link AccessPermission}. + * <p> + * The possible target names for use with a Reggie server are specified in the + * package documentation for {@link org.apache.river.reggie}. + * + * @author Sun Microsystems, Inc. + * @since 2.0 + */ +public class RegistrarPermission extends AccessPermission { + + private static final long serialVersionUID = 2L; + + /** + * Creates an instance with the specified target name. + * + * @param name the target name + * @throws NullPointerException if the target name is <code>null</code> + * @throws IllegalArgumentException if the target name does not match + * the syntax specified in the comments at the beginning of the {@link + * AccessPermission} class + */ + public RegistrarPermission(String name) { + super(name); + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarProxy.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarProxy.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarProxy.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RegistrarProxy.java Sun Jul 5 11:41:39 2020 @@ -1,282 +1,282 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.reggie; - -import org.apache.river.proxy.MarshalledWrapper; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.rmi.RemoteException; -import java.rmi.MarshalledObject; -import java.rmi.UnmarshalException; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.jini.admin.Administrable; -import net.jini.core.constraint.RemoteMethodControl; -import net.jini.core.discovery.LookupLocator; -import net.jini.core.event.EventRegistration; -import net.jini.core.event.RemoteEventListener; -import net.jini.core.lookup.ServiceID; -import net.jini.core.lookup.ServiceItem; -import net.jini.core.lookup.ServiceMatches; -import net.jini.core.lookup.ServiceRegistrar; -import net.jini.core.lookup.ServiceRegistration; -import net.jini.core.lookup.ServiceTemplate; -import net.jini.id.ReferentUuid; -import net.jini.id.ReferentUuids; -import net.jini.id.Uuid; -import net.jini.id.UuidFactory; - -/** - * A RegistrarProxy is a proxy for a registrar. Clients only see instances - * via the ServiceRegistrar, Administrable and ReferentUuid interfaces. - * - * @author Sun Microsystems, Inc. - * - */ -class RegistrarProxy - implements ServiceRegistrar, Administrable, ReferentUuid, Serializable -{ - private static final long serialVersionUID = 2L; - - private static final Logger logger = - Logger.getLogger("org.apache.river.reggie"); - - /** - * The registrar. - * - * @serial - */ - final Registrar server; - /** - * The registrar's service ID. - */ - transient ServiceID registrarID; - - /** - * Returns RegistrarProxy or ConstrainableRegistrarProxy instance, - * depending on whether given server implements RemoteMethodControl. - */ - static RegistrarProxy getInstance(Registrar server, - ServiceID registrarID) - { - return (server instanceof RemoteMethodControl) ? - new ConstrainableRegistrarProxy(server, registrarID, null) : - new RegistrarProxy(server, registrarID); - } - - /** Constructor for use by getInstance(), ConstrainableRegistrarProxy. */ - RegistrarProxy(Registrar server, ServiceID registrarID) { - this.server = server; - this.registrarID = registrarID; - } - - // Inherit javadoc - public Object getAdmin() throws RemoteException { - return server.getAdmin(); - } - - // Inherit javadoc - public ServiceRegistration register(ServiceItem srvItem, - long leaseDuration) - throws RemoteException - { - Item item = new Item(srvItem); - if (item.serviceID != null) { - Util.checkRegistrantServiceID( - item.serviceID, logger, Level.WARNING); - } - return server.register(item, leaseDuration); - } - - // Inherit javadoc - public Object lookup(ServiceTemplate tmpl) throws RemoteException { - MarshalledWrapper wrapper = server.lookup(new Template(tmpl)); - if (wrapper == null) - return null; - try { - return wrapper.get(); - } catch (IOException e) { - throw new UnmarshalException("error unmarshalling return", e); - } catch (ClassNotFoundException e) { - throw new UnmarshalException("error unmarshalling return", e); - } - } - - // Inherit javadoc - public ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches) - throws RemoteException - { - return server.lookup(new Template(tmpl), maxMatches).get(); - } - - // Inherit javadoc - public EventRegistration notify(ServiceTemplate tmpl, - int transitions, - RemoteEventListener listener, - MarshalledObject handback, - long leaseDuration) - throws RemoteException - { - return server.notify(new Template(tmpl), transitions, listener, - handback, leaseDuration); - } - - // Inherit javadoc - public Class[] getEntryClasses(ServiceTemplate tmpl) - throws RemoteException - { - return EntryClassBase.toClass( - server.getEntryClasses(new Template(tmpl))); - } - - // Inherit javadoc - public Object[] getFieldValues(ServiceTemplate tmpl, - int setIndex, String field) - throws NoSuchFieldException, RemoteException - { - /* check that setIndex and field are valid, convert field to index */ - ClassMapper.EntryField[] efields = - ClassMapper.getFields( - tmpl.attributeSetTemplates[setIndex].getClass()); - int fidx; - for (fidx = efields.length; --fidx >= 0; ) { - if (field.equals(efields[fidx].field.getName())) - break; - } - if (fidx < 0) - throw new NoSuchFieldException(field); - Object[] values = server.getFieldValues(new Template(tmpl), - setIndex, fidx); - /* unmarshal each value, replacing with null on exception */ - if (values != null && efields[fidx].marshal) { - for (int i = values.length; --i >= 0; ) { - try { - values[i] = ((MarshalledWrapper) values[i]).get(); - continue; - } catch (Throwable e) { - handleException(e); - } - values[i] = null; - } - } - return values; - } - - /** - * Rethrow the exception if it is an Error, unless it is a LinkageError, - * OutOfMemoryError, or StackOverflowError. Otherwise print the - * exception stack trace if debugging is enabled. - */ - static void handleException(final Throwable e) { - if (e instanceof Error && - !(e instanceof LinkageError || - e instanceof OutOfMemoryError || - e instanceof StackOverflowError)) - { - throw (Error)e; - } - logger.log(Level.INFO, "unmarshalling failure", e); - } - - // Inherit javadoc - public Class[] getServiceTypes(ServiceTemplate tmpl, String prefix) - throws RemoteException - { - return ServiceTypeBase.toClass( - server.getServiceTypes(new Template(tmpl), - prefix)); - } - - public ServiceID getServiceID() { - return registrarID; - } - - // Inherit javadoc - public LookupLocator getLocator() throws RemoteException { - return server.getLocator(); - } - - // Inherit javadoc - public String[] getGroups() throws RemoteException { - return server.getMemberGroups(); - } - - // Inherit javadoc - public Uuid getReferentUuid() { - return UuidFactory.create(registrarID.getMostSignificantBits(), - registrarID.getLeastSignificantBits()); - } - - // Inherit javadoc - public int hashCode() { - return registrarID.hashCode(); - } - - /** Proxies for servers with the same service ID are considered equal. */ - public boolean equals(Object obj) { - return ReferentUuids.compare(this, obj); - } - - /** - * Returns a string created from the proxy class name, the registrar's - * service ID, and the result of the underlying proxy's toString method. - * - * @return String - */ - public String toString() { - return this.getClass().getName() + "[registrar=" + registrarID - + " " + server + "]"; - } - - /** - * Writes the default serializable field value for this instance, followed - * by the registrar's service ID encoded as specified by the - * ServiceID.writeBytes method. - */ - private void writeObject(ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - registrarID.writeBytes(out); - } - - /** - * Reads the default serializable field value for this instance, followed - * by the registrar's service ID encoded as specified by the - * ServiceID.writeBytes method. Verifies that the deserialized registrar - * reference is non-null. - */ - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException - { - in.defaultReadObject(); - registrarID = new ServiceID(in); - if (server == null) { - throw new InvalidObjectException("null server"); - } - } - - /** - * Throws InvalidObjectException, since data for this class is required. - */ - private void readObjectNoData() throws ObjectStreamException { - throw new InvalidObjectException("no data"); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.reggie.proxy; + +import org.apache.river.proxy.MarshalledWrapper; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.rmi.RemoteException; +import java.rmi.MarshalledObject; +import java.rmi.UnmarshalException; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.jini.admin.Administrable; +import net.jini.core.constraint.RemoteMethodControl; +import net.jini.core.discovery.LookupLocator; +import net.jini.core.event.EventRegistration; +import net.jini.core.event.RemoteEventListener; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceItem; +import net.jini.core.lookup.ServiceMatches; +import net.jini.core.lookup.ServiceRegistrar; +import net.jini.core.lookup.ServiceRegistration; +import net.jini.core.lookup.ServiceTemplate; +import net.jini.id.ReferentUuid; +import net.jini.id.ReferentUuids; +import net.jini.id.Uuid; +import net.jini.id.UuidFactory; + +/** + * A RegistrarProxy is a proxy for a registrar. Clients only see instances + * via the ServiceRegistrar, Administrable and ReferentUuid interfaces. + * + * @author Sun Microsystems, Inc. + * + */ +public class RegistrarProxy + implements ServiceRegistrar, Administrable, ReferentUuid, Serializable +{ + private static final long serialVersionUID = 2L; + + private static final Logger logger = + Logger.getLogger("org.apache.river.reggie"); + + /** + * The registrar. + * + * @serial + */ + final Registrar server; + /** + * The registrar's service ID. + */ + transient ServiceID registrarID; + + /** + * Returns RegistrarProxy or ConstrainableRegistrarProxy instance, + * depending on whether given server implements RemoteMethodControl. + */ + public static RegistrarProxy getInstance(Registrar server, + ServiceID registrarID) + { + return (server instanceof RemoteMethodControl) ? + new ConstrainableRegistrarProxy(server, registrarID, null) : + new RegistrarProxy(server, registrarID); + } + + /** Constructor for use by getInstance(), ConstrainableRegistrarProxy. */ + RegistrarProxy(Registrar server, ServiceID registrarID) { + this.server = server; + this.registrarID = registrarID; + } + + // Inherit javadoc + public Object getAdmin() throws RemoteException { + return server.getAdmin(); + } + + // Inherit javadoc + public ServiceRegistration register(ServiceItem srvItem, + long leaseDuration) + throws RemoteException + { + Item item = new Item(srvItem); + if (item.serviceID != null) { + Util.checkRegistrantServiceID( + item.serviceID, logger, Level.WARNING); + } + return server.register(item, leaseDuration); + } + + // Inherit javadoc + public Object lookup(ServiceTemplate tmpl) throws RemoteException { + MarshalledWrapper wrapper = server.lookup(new Template(tmpl)); + if (wrapper == null) + return null; + try { + return wrapper.get(); + } catch (IOException e) { + throw new UnmarshalException("error unmarshalling return", e); + } catch (ClassNotFoundException e) { + throw new UnmarshalException("error unmarshalling return", e); + } + } + + // Inherit javadoc + public ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches) + throws RemoteException + { + return server.lookup(new Template(tmpl), maxMatches).get(); + } + + // Inherit javadoc + public EventRegistration notify(ServiceTemplate tmpl, + int transitions, + RemoteEventListener listener, + MarshalledObject handback, + long leaseDuration) + throws RemoteException + { + return server.notify(new Template(tmpl), transitions, listener, + handback, leaseDuration); + } + + // Inherit javadoc + public Class[] getEntryClasses(ServiceTemplate tmpl) + throws RemoteException + { + return EntryClassBase.toClass( + server.getEntryClasses(new Template(tmpl))); + } + + // Inherit javadoc + public Object[] getFieldValues(ServiceTemplate tmpl, + int setIndex, String field) + throws NoSuchFieldException, RemoteException + { + /* check that setIndex and field are valid, convert field to index */ + ClassMapper.EntryField[] efields = + ClassMapper.getFields( + tmpl.attributeSetTemplates[setIndex].getClass()); + int fidx; + for (fidx = efields.length; --fidx >= 0; ) { + if (field.equals(efields[fidx].field.getName())) + break; + } + if (fidx < 0) + throw new NoSuchFieldException(field); + Object[] values = server.getFieldValues(new Template(tmpl), + setIndex, fidx); + /* unmarshal each value, replacing with null on exception */ + if (values != null && efields[fidx].marshal) { + for (int i = values.length; --i >= 0; ) { + try { + values[i] = ((MarshalledWrapper) values[i]).get(); + continue; + } catch (Throwable e) { + handleException(e); + } + values[i] = null; + } + } + return values; + } + + /** + * Rethrow the exception if it is an Error, unless it is a LinkageError, + * OutOfMemoryError, or StackOverflowError. Otherwise print the + * exception stack trace if debugging is enabled. + */ + static void handleException(final Throwable e) { + if (e instanceof Error && + !(e instanceof LinkageError || + e instanceof OutOfMemoryError || + e instanceof StackOverflowError)) + { + throw (Error)e; + } + logger.log(Level.INFO, "unmarshalling failure", e); + } + + // Inherit javadoc + public Class[] getServiceTypes(ServiceTemplate tmpl, String prefix) + throws RemoteException + { + return ServiceTypeBase.toClass( + server.getServiceTypes(new Template(tmpl), + prefix)); + } + + public ServiceID getServiceID() { + return registrarID; + } + + // Inherit javadoc + public LookupLocator getLocator() throws RemoteException { + return server.getLocator(); + } + + // Inherit javadoc + public String[] getGroups() throws RemoteException { + return server.getMemberGroups(); + } + + // Inherit javadoc + public Uuid getReferentUuid() { + return UuidFactory.create(registrarID.getMostSignificantBits(), + registrarID.getLeastSignificantBits()); + } + + // Inherit javadoc + public int hashCode() { + return registrarID.hashCode(); + } + + /** Proxies for servers with the same service ID are considered equal. */ + public boolean equals(Object obj) { + return ReferentUuids.compare(this, obj); + } + + /** + * Returns a string created from the proxy class name, the registrar's + * service ID, and the result of the underlying proxy's toString method. + * + * @return String + */ + public String toString() { + return this.getClass().getName() + "[registrar=" + registrarID + + " " + server + "]"; + } + + /** + * Writes the default serializable field value for this instance, followed + * by the registrar's service ID encoded as specified by the + * ServiceID.writeBytes method. + */ + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + registrarID.writeBytes(out); + } + + /** + * Reads the default serializable field value for this instance, followed + * by the registrar's service ID encoded as specified by the + * ServiceID.writeBytes method. Verifies that the deserialized registrar + * reference is non-null. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + registrarID = new ServiceID(in); + if (server == null) { + throw new InvalidObjectException("null server"); + } + } + + /** + * Throws InvalidObjectException, since data for this class is required. + */ + private void readObjectNoData() throws ObjectStreamException { + throw new InvalidObjectException("no data"); + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/Registration.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/Registration.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/Registration.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/Registration.java Sun Jul 5 11:41:39 2020 @@ -1,157 +1,157 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.reggie; - -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.rmi.RemoteException; -import net.jini.core.constraint.RemoteMethodControl; -import net.jini.core.entry.Entry; -import net.jini.core.lease.Lease; -import net.jini.core.lease.UnknownLeaseException; -import net.jini.core.lookup.ServiceID; -import net.jini.core.lookup.ServiceRegistration; -import net.jini.id.ReferentUuid; -import net.jini.id.ReferentUuids; -import net.jini.id.Uuid; - -/** - * Implementation class for the ServiceRegistration interface. - * - * @author Sun Microsystems, Inc. - * - */ -class Registration implements ServiceRegistration, ReferentUuid, Serializable { - - private static final long serialVersionUID = 2L; - - /** - * The registrar - * - * @serial - */ - final Registrar server; - /** - * The service lease - * - * @serial - */ - final ServiceLease lease; - - /** - * Returns Registration or ConstrainableRegistration instance, depending on - * whether given server implements RemoteMethodControl. - */ - static Registration getInstance(Registrar server, ServiceLease lease) { - return (server instanceof RemoteMethodControl) ? - new ConstrainableRegistration(server, lease, null) : - new Registration(server, lease); - } - - /** Constructor for use by getInstance(), ConstrainableRegistration. */ - Registration(Registrar server, ServiceLease lease) { - this.server = server; - this.lease = lease; - } - - // This method's javadoc is inherited from an interface of this class - public ServiceID getServiceID() { - return lease.getServiceID(); - } - - // This method's javadoc is inherited from an interface of this class - public Lease getLease() { - return lease; - } - - // This method's javadoc is inherited from an interface of this class - public void addAttributes(Entry[] attrSets) - throws UnknownLeaseException, RemoteException - { - server.addAttributes(lease.getServiceID(), - lease.getReferentUuid(), - EntryRep.toEntryRep(attrSets, true)); - } - - // This method's javadoc is inherited from an interface of this class - public void modifyAttributes(Entry[] attrSetTmpls, Entry[] attrSets) - throws UnknownLeaseException, RemoteException - { - server.modifyAttributes(lease.getServiceID(), - lease.getReferentUuid(), - EntryRep.toEntryRep(attrSetTmpls, false), - EntryRep.toEntryRep(attrSets, false)); - } - - // This method's javadoc is inherited from an interface of this class - public void setAttributes(Entry[] attrSets) - throws UnknownLeaseException, RemoteException - { - server.setAttributes(lease.getServiceID(), - lease.getReferentUuid(), - EntryRep.toEntryRep(attrSets, true)); - } - - // This method's javadoc is inherited from an interface of this class - public Uuid getReferentUuid() { - return lease.getReferentUuid(); - } - - /** Returns the registration Uuid's hash code. */ - public int hashCode() { - return lease.getReferentUuid().hashCode(); - } - - /** Returns true if registration Uuids match, false otherwise. */ - public boolean equals(Object obj) { - return ReferentUuids.compare(this, obj); - } - - /** - * Returns a string created from the proxy class name and the result - * of calling toString on the contained lease. - * - * @return String - */ - public String toString() { - return getClass().getName() + "[" + lease + "]"; - } - - - /** Verifies that member fields are non-null. */ - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException - { - in.defaultReadObject(); - if (server == null) { - throw new InvalidObjectException("null server"); - } else if (lease == null) { - throw new InvalidObjectException("null lease"); - } - } - - /** - * Throws InvalidObjectException, since data for this class is required. - */ - private void readObjectNoData() throws ObjectStreamException { - throw new InvalidObjectException("no data"); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.reggie.proxy; + +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.rmi.RemoteException; +import net.jini.core.constraint.RemoteMethodControl; +import net.jini.core.entry.Entry; +import net.jini.core.lease.Lease; +import net.jini.core.lease.UnknownLeaseException; +import net.jini.core.lookup.ServiceID; +import net.jini.core.lookup.ServiceRegistration; +import net.jini.id.ReferentUuid; +import net.jini.id.ReferentUuids; +import net.jini.id.Uuid; + +/** + * Implementation class for the ServiceRegistration interface. + * + * @author Sun Microsystems, Inc. + * + */ +public class Registration implements ServiceRegistration, ReferentUuid, Serializable { + + private static final long serialVersionUID = 2L; + + /** + * The registrar + * + * @serial + */ + final Registrar server; + /** + * The service lease + * + * @serial + */ + final ServiceLease lease; + + /** + * Returns Registration or ConstrainableRegistration instance, depending on + * whether given server implements RemoteMethodControl. + */ + public static Registration getInstance(Registrar server, ServiceLease lease) { + return (server instanceof RemoteMethodControl) ? + new ConstrainableRegistration(server, lease, null) : + new Registration(server, lease); + } + + /** Constructor for use by getInstance(), ConstrainableRegistration. */ + Registration(Registrar server, ServiceLease lease) { + this.server = server; + this.lease = lease; + } + + // This method's javadoc is inherited from an interface of this class + public ServiceID getServiceID() { + return lease.getServiceID(); + } + + // This method's javadoc is inherited from an interface of this class + public Lease getLease() { + return lease; + } + + // This method's javadoc is inherited from an interface of this class + public void addAttributes(Entry[] attrSets) + throws UnknownLeaseException, RemoteException + { + server.addAttributes(lease.getServiceID(), + lease.getReferentUuid(), + EntryRep.toEntryRep(attrSets, true)); + } + + // This method's javadoc is inherited from an interface of this class + public void modifyAttributes(Entry[] attrSetTmpls, Entry[] attrSets) + throws UnknownLeaseException, RemoteException + { + server.modifyAttributes(lease.getServiceID(), + lease.getReferentUuid(), + EntryRep.toEntryRep(attrSetTmpls, false), + EntryRep.toEntryRep(attrSets, false)); + } + + // This method's javadoc is inherited from an interface of this class + public void setAttributes(Entry[] attrSets) + throws UnknownLeaseException, RemoteException + { + server.setAttributes(lease.getServiceID(), + lease.getReferentUuid(), + EntryRep.toEntryRep(attrSets, true)); + } + + // This method's javadoc is inherited from an interface of this class + public Uuid getReferentUuid() { + return lease.getReferentUuid(); + } + + /** Returns the registration Uuid's hash code. */ + public int hashCode() { + return lease.getReferentUuid().hashCode(); + } + + /** Returns true if registration Uuids match, false otherwise. */ + public boolean equals(Object obj) { + return ReferentUuids.compare(this, obj); + } + + /** + * Returns a string created from the proxy class name and the result + * of calling toString on the contained lease. + * + * @return String + */ + public String toString() { + return getClass().getName() + "[" + lease + "]"; + } + + + /** Verifies that member fields are non-null. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + if (server == null) { + throw new InvalidObjectException("null server"); + } else if (lease == null) { + throw new InvalidObjectException("null lease"); + } + } + + /** + * Throws InvalidObjectException, since data for this class is required. + */ + private void readObjectNoData() throws ObjectStreamException { + throw new InvalidObjectException("no data"); + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RenewResults.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RenewResults.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RenewResults.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/RenewResults.java Sun Jul 5 11:41:39 2020 @@ -1,57 +1,57 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.reggie; - -import java.io.Serializable; - -/* - * RenewResults contains the return values of a renewLeases call on the - * registrar. Instances are never visible to clients, they are private - * to the communication between the LeaseMap proxy and the registrar. - * - * @author Sun Microsystems, Inc. - * - */ -class RenewResults implements Serializable { - - private static final long serialVersionUID = 2L; - - /** - * The granted duration for each lease. The length of this array - * is the same as the length of the durations parameter to renewLeases, - * and is in the same order. If a duration is -1, it indicates that - * an exception was thrown for this lease. - * - * @serial - */ - public long[] durations; - /** - * Any exceptions thrown. The length of this array is the same as - * the number of -1 elements in durations. The exceptions are in - * order. - * - * @serial - */ - public Exception[] exceptions; - - /** Simple constructor */ - public RenewResults(long[] durations, Exception[] exceptions) { - this.durations = durations; - this.exceptions = exceptions; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.reggie.proxy; + +import java.io.Serializable; + +/* + * RenewResults contains the return values of a renewLeases call on the + * registrar. Instances are never visible to clients, they are private + * to the communication between the LeaseMap proxy and the registrar. + * + * @author Sun Microsystems, Inc. + * + */ +public class RenewResults implements Serializable { + + private static final long serialVersionUID = 2L; + + /** + * The granted duration for each lease. The length of this array + * is the same as the length of the durations parameter to renewLeases, + * and is in the same order. If a duration is -1, it indicates that + * an exception was thrown for this lease. + * + * @serial + */ + public long[] durations; + /** + * Any exceptions thrown. The length of this array is the same as + * the number of -1 elements in durations. The exceptions are in + * order. + * + * @serial + */ + public Exception[] exceptions; + + /** Simple constructor */ + public RenewResults(long[] durations, Exception[] exceptions) { + this.durations = durations; + this.exceptions = exceptions; + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/ServiceLease.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/ServiceLease.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/ServiceLease.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/reggie/reggie-dl/src/main/java/org/apache/river/reggie/proxy/ServiceLease.java Sun Jul 5 11:41:39 2020 @@ -1,128 +1,128 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.reggie; - -import java.rmi.RemoteException; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamException; -import net.jini.core.constraint.RemoteMethodControl; -import net.jini.core.lease.UnknownLeaseException; -import net.jini.core.lookup.ServiceID; -import net.jini.id.Uuid; - -/** - * A ServiceLease is a proxy for a service registration lease at a registrar. - * Clients only see instances via the Lease interface. - * - * @author Sun Microsystems, Inc. - * - */ -class ServiceLease extends RegistrarLease { - - private static final long serialVersionUID = 2L; - /** The type of the lease used in toString() calls. */ - private static final String LEASE_TYPE = "service"; - - /** - * The service id assigned at registration. - */ - transient ServiceID serviceID; - - /** - * Returns ServiceLease or ConstrainableServiceLease instance, depending on - * whether given server implements RemoteMethodControl. - */ - static ServiceLease getInstance(Registrar server, - ServiceID registrarID, - ServiceID serviceID, - Uuid leaseID, - long expiration) - { - return (server instanceof RemoteMethodControl) ? - new ConstrainableServiceLease( - server, registrarID, serviceID, leaseID, expiration, null) : - new ServiceLease( - server, registrarID, serviceID, leaseID, expiration); - } - - /** Constructor for use by getInstance(), ConstrainableServiceLease. */ - ServiceLease(Registrar server, - ServiceID registrarID, - ServiceID serviceID, - Uuid leaseID, - long expiration) - { - super(server, registrarID, leaseID, expiration); - this.serviceID = serviceID; - } - - public void cancel() throws UnknownLeaseException, RemoteException { - server.cancelServiceLease(serviceID, leaseID); - } - - /** Do the actual renew. */ - protected long doRenew(long duration) - throws UnknownLeaseException, RemoteException - { - return server.renewServiceLease(serviceID, leaseID, duration); - } - - /** Returns the service ID */ - ServiceID getServiceID() { - return serviceID; - } - - Object getRegID() { - return serviceID; - } - - // This method's javadoc is inherited from a super class of this class - String getLeaseType() { - return LEASE_TYPE; - } - - /** - * Writes the service ID, encoded as specified by the ServiceID.writeBytes - * method. - */ - private void writeObject(ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - serviceID.writeBytes(out); - } - - /** - * Reads the service ID, encoded as specified by the ServiceID.writeBytes - * method. - */ - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException - { - in.defaultReadObject(); - serviceID = new ServiceID(in); - } - - /** - * Throws InvalidObjectException, since data for this class is required. - */ - private void readObjectNoData() throws ObjectStreamException { - throw new InvalidObjectException("no data"); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.reggie.proxy; + +import java.rmi.RemoteException; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import net.jini.core.constraint.RemoteMethodControl; +import net.jini.core.lease.UnknownLeaseException; +import net.jini.core.lookup.ServiceID; +import net.jini.id.Uuid; + +/** + * A ServiceLease is a proxy for a service registration lease at a registrar. + * Clients only see instances via the Lease interface. + * + * @author Sun Microsystems, Inc. + * + */ +public class ServiceLease extends RegistrarLease { + + private static final long serialVersionUID = 2L; + /** The type of the lease used in toString() calls. */ + private static final String LEASE_TYPE = "service"; + + /** + * The service id assigned at registration. + */ + transient ServiceID serviceID; + + /** + * Returns ServiceLease or ConstrainableServiceLease instance, depending on + * whether given server implements RemoteMethodControl. + */ + public static ServiceLease getInstance(Registrar server, + ServiceID registrarID, + ServiceID serviceID, + Uuid leaseID, + long expiration) + { + return (server instanceof RemoteMethodControl) ? + new ConstrainableServiceLease( + server, registrarID, serviceID, leaseID, expiration, null) : + new ServiceLease( + server, registrarID, serviceID, leaseID, expiration); + } + + /** Constructor for use by getInstance(), ConstrainableServiceLease. */ + ServiceLease(Registrar server, + ServiceID registrarID, + ServiceID serviceID, + Uuid leaseID, + long expiration) + { + super(server, registrarID, leaseID, expiration); + this.serviceID = serviceID; + } + + public void cancel() throws UnknownLeaseException, RemoteException { + server.cancelServiceLease(serviceID, leaseID); + } + + /** Do the actual renew. */ + protected long doRenew(long duration) + throws UnknownLeaseException, RemoteException + { + return server.renewServiceLease(serviceID, leaseID, duration); + } + + /** Returns the service ID */ + ServiceID getServiceID() { + return serviceID; + } + + Object getRegID() { + return serviceID; + } + + // This method's javadoc is inherited from a super class of this class + String getLeaseType() { + return LEASE_TYPE; + } + + /** + * Writes the service ID, encoded as specified by the ServiceID.writeBytes + * method. + */ + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + serviceID.writeBytes(out); + } + + /** + * Reads the service ID, encoded as specified by the ServiceID.writeBytes + * method. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + serviceID = new ServiceID(in); + } + + /** + * Throws InvalidObjectException, since data for this class is required. + */ + private void readObjectNoData() throws ObjectStreamException { + throw new InvalidObjectException("no data"); + } +}
