Modified: river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/OutriggerServerWrapper.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/OutriggerServerWrapper.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/OutriggerServerWrapper.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/OutriggerServerWrapper.java Sun Jul 5 11:41:39 2020 @@ -1,492 +1,499 @@ -/* - * 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.outrigger; - -import java.util.Map; -import java.io.IOException; -import java.rmi.Remote; -import java.rmi.MarshalledObject; -import java.rmi.RemoteException; -import java.rmi.activation.ActivationID; -import java.rmi.activation.ActivationException; -import javax.security.auth.login.LoginException; - -import net.jini.core.discovery.LookupLocator; -import net.jini.core.entry.Entry; -import net.jini.core.event.EventRegistration; -import net.jini.core.event.RemoteEventListener; -import net.jini.core.transaction.Transaction; -import net.jini.core.transaction.TransactionException; -import net.jini.core.transaction.UnknownTransactionException; -import net.jini.core.transaction.server.TransactionManager; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseDeniedException; -import net.jini.core.lease.UnknownLeaseException; -import net.jini.export.ProxyAccessor; -import net.jini.space.JavaSpace; -import net.jini.space.InternalSpaceException; - -import net.jini.security.TrustVerifier; -import net.jini.security.proxytrust.ServerProxyTrust; -import net.jini.config.ConfigurationException; -import net.jini.id.Uuid; - -import org.apache.river.start.LifeCycle; -import org.apache.river.api.util.Startable; - -/** - * For various reasons there is code that we would like - * to run before every incoming remote call. To accomplish - * this we wrap the server in an object that will run - * the common code and then delegate to the server to - * do the actual work. This is a base class for these - * wrappers. - * - * @author Sun Microsystems, Inc. - * @since 2.0 - */ -class OutriggerServerWrapper - implements OutriggerServer, ServerProxyTrust, ProxyAccessor, Startable -{ - /** The object being delegated to */ - private final OutriggerServerImpl delegate; - - /** - * If <code>false</code>, hold calls until it becomes - * <code>true</code> - */ - private boolean allowCalls; - - /** - * If non-null cause incoming calls to immediately throw this - * exception. Takes presidents over <code>holdCalls</code>. This - * field is only set to an <code>Error</code>, - * <code>RemoteException</code>, or <code>RuntimeException</code> - * and thus can be thrown by an of <code>OutriggerServer</code>'s - * methods. - */ - private Throwable failCallsWith; - - /** - * Create an <code>OutriggerServerWrapper</code> that - * will delegate to a non-activatable <code>OutriggerServerImpl</code> - * created with the specified configuration and wrapped by - * <code>this</code>. - * @param configArgs set of strings to be used to obtain a - * <code>Configuration</code>. - * @param lifeCycle the object to notify when this - * service is destroyed. - * @param persistent If <code>true</code> will throw an - * <code>ConfigurationException</code> - * if there is no persistence directory or - * store specified in the configuration. - * @throws IOException if there is problem exporting the server. - * @throws ConfigurationException if the <code>Configuration</code> is - * malformed. - * @throws LoginException if the <code>loginContext</code> specified - * in the configuration is non-null and throws - * an exception when login is attempted. - */ - OutriggerServerWrapper(String[] configArgs, LifeCycle lifeCycle, - boolean persistent) - throws IOException, ConfigurationException, LoginException - { - try { - delegate = new OutriggerServerImpl(null, lifeCycle, configArgs, - persistent, this); - } catch (ActivationException e) { - throw new AssertionError(e); - } - } - - /** - * Create an <code>OutriggerServerWrapper</code> that - * will delegate to an <code>OutriggerServerImpl</code> - * created with the specified argument and wrapped by <code>this</code>. - * @param activationID of the server, must not be <code>null</code>. - * @param configArgs set of strings to be used to obtain a - * <code>Configuration</code>. - * @throws IOException if there is problem recovering data - * from disk, exporting the server, or unpacking - * <code>data</code>. - * @throws ConfigurationException if the <code>Configuration</code> is - * malformed. - * @throws ActivationException if activatable and there - * is a problem getting a reference to the activation system. - * @throws LoginException if the <code>loginContext</code> specified - * in the configuration is non-null and throws - * an exception when login is attempted. - * @throws NullPointerException if <code>activationID</code> - * is <code>null</code>. - */ - OutriggerServerWrapper(ActivationID activationID, String[] configArgs) - throws IOException, ConfigurationException, LoginException, - ActivationException - { - if (activationID == null) - throw new NullPointerException("activationID must be non-null"); - delegate = new OutriggerServerImpl(activationID, null, configArgs, - true, this); - } - - /** - * Cause incoming calls to block until further notice. - */ - synchronized void holdCalls() { - failCallsWith = null; - allowCalls = false; - notifyAll(); - } - - /** - * Cause in new or blocked calls to fail with - * the specified exception. - * @throws IllegalArgumentException if <code>t</code> - * is not an <code>Error</code>, <code>RemoteException</code>, - * or <code>RuntimeException</code>. - * @throws NullPointerException if <code>t</code> is <code>null</code>. - */ - synchronized void rejectCalls(Throwable t) { - if (t == null) - throw new NullPointerException("Throwable must not be null"); - - if (!((t instanceof Error) || - (t instanceof RuntimeException) || - (t instanceof RemoteException))) - throw new IllegalArgumentException("t must be an exception " + - "that can be thrown from any of OutriggerServer's methods"); - - failCallsWith = t; - allowCalls = true; - notifyAll(); - } - - /** - * Allow incoming calls. - */ - synchronized void allowCalls() { - failCallsWith = null; - allowCalls = true; - notifyAll(); - } - - /** - * Block until calls are allowed, or until calls - * are to be rejected. - * @throws RemoteException If calls are being rejected - * with <code>RemoteException</code>s. - * @throws RuntimeException If calls are being rejected - * with <code>RuntimeException</code>s. - * @throws Error If calls are being rejected - * with <code>Error</code>s. - */ - private synchronized void gate() throws RemoteException { - while (!allowCalls || failCallsWith != null) { - if (failCallsWith != null) { - if (failCallsWith instanceof RemoteException) - throw (RemoteException)failCallsWith; - else if (failCallsWith instanceof Error) - throw (Error)failCallsWith; - else if (failCallsWith instanceof RuntimeException) - throw (RuntimeException)failCallsWith; - else - throw new AssertionError("Wrapper trying to " + - "throw " + failCallsWith); - } - - if (!allowCalls) { - try { - wait(); - } catch (InterruptedException e) { - throw new - InternalSpaceException("gate method interrupted"); - } - } - } - } - - - public long[] write(EntryRep entry, Transaction txn, long lease) - throws TransactionException, RemoteException - { - gate(); - return delegate.write(entry, txn, lease); - } - - public Object read(EntryRep tmpl, Transaction txn, long timeout, - QueryCookie cookie) - throws TransactionException, RemoteException, InterruptedException - { - gate(); - return delegate.read(tmpl, txn, timeout, cookie); - } - - public Object readIfExists(EntryRep tmpl, Transaction txn, long timeout, - QueryCookie cookie) - throws TransactionException, RemoteException, InterruptedException - { - gate(); - return delegate.readIfExists(tmpl, txn, timeout, cookie); - } - - public Object take(EntryRep tmpl, Transaction txn, long timeout, - QueryCookie cookie) - throws TransactionException, RemoteException, InterruptedException - { - gate(); - return delegate.take(tmpl, txn, timeout, cookie); - } - - public Object takeIfExists(EntryRep tmpl, Transaction txn, long timeout, - QueryCookie cookie) - throws TransactionException, RemoteException, InterruptedException - { - gate(); - return delegate.takeIfExists(tmpl, txn, timeout, cookie); - } - - public EventRegistration - notify(EntryRep tmpl, Transaction txn, RemoteEventListener listener, - long lease, MarshalledObject handback) - throws TransactionException, RemoteException - { - gate(); - return delegate.notify(tmpl, txn, listener, lease, handback); - } - - public EventRegistration registerForAvailabilityEvent(EntryRep[] tmpls, - Transaction txn, boolean visibilityOnly, RemoteEventListener listener, - long leaseTime, MarshalledObject handback) - throws TransactionException, RemoteException - { - gate(); - return delegate.registerForAvailabilityEvent(tmpls, txn, visibilityOnly, - listener, leaseTime, handback); - } - - public long[] write(EntryRep[] entries, Transaction txn, long[] leaseTimes) - throws TransactionException, RemoteException - { - gate(); - return delegate.write(entries, txn, leaseTimes); - } - - public Object take(EntryRep[] tmpls, Transaction tr, long timeout, - int limit, QueryCookie cookie) - throws TransactionException, RemoteException - { - gate(); - return delegate.take(tmpls, tr, timeout, limit, cookie); - } - - public MatchSetData contents(EntryRep[] tmpls, Transaction tr, - long leaseTime, long limit) - throws TransactionException, RemoteException - { - gate(); - return delegate.contents(tmpls, tr, leaseTime, limit); - } - - public EntryRep[] nextBatch(Uuid contentsQueryUuid, Uuid entryUuid) - throws RemoteException - { - gate(); - return delegate.nextBatch(contentsQueryUuid, entryUuid); - } - - public long renew(Uuid cookie, long extension) - throws LeaseDeniedException, UnknownLeaseException, RemoteException - { - gate(); - return delegate.renew(cookie, extension); - } - - public void cancel(Uuid cookie) - throws UnknownLeaseException, RemoteException - { - gate(); - delegate.cancel(cookie); - } - - public Object getAdmin() throws RemoteException { - gate(); - return delegate.getAdmin(); - } - - public int prepare(TransactionManager mgr, long id) - throws UnknownTransactionException, RemoteException - { - gate(); - return delegate.prepare(mgr, id); - } - - public void commit(TransactionManager mgr, long id) - throws UnknownTransactionException, RemoteException - { - gate(); - delegate.commit(mgr, id); - } - - public void abort(TransactionManager mgr, long id) - throws UnknownTransactionException, RemoteException - { - gate(); - delegate.abort(mgr, id); - } - - public int prepareAndCommit(TransactionManager mgr, long id) - throws UnknownTransactionException, RemoteException - { - gate(); - return delegate.prepareAndCommit(mgr, id); - } - - public RenewResults renewAll(Uuid[] cookies, long[] durations) - throws RemoteException - { - gate(); - return delegate.renewAll(cookies, durations); - } - - public Map cancelAll(Uuid[] cookies) throws RemoteException { - gate(); - return delegate.cancelAll(cookies); - } - - public Object getServiceProxy() throws RemoteException { - gate(); - return delegate.getServiceProxy(); - } - - public JavaSpace space() throws RemoteException { - gate(); - return delegate.space(); - } - - public Uuid contents(EntryRep tmpl, Transaction txn) - throws TransactionException, RemoteException - { - gate(); - return delegate.contents(tmpl, txn); - } - - public EntryRep[] nextReps(Uuid iterationUuid, int max, - Uuid entryUuid) - throws RemoteException - { - gate(); - return delegate.nextReps(iterationUuid, max, entryUuid); - } - - public void delete(Uuid iterationUuid, Uuid entryUuid) - throws RemoteException - { - gate(); - delegate.delete(iterationUuid, entryUuid); - } - - public void close(Uuid iterationUuid) throws RemoteException { - gate(); - delegate.close(iterationUuid); - } - - public void destroy() throws RemoteException { - gate(); - delegate.destroy(); - } - - public Entry[] getLookupAttributes() throws RemoteException { - gate(); - return delegate.getLookupAttributes(); - } - - public void addLookupAttributes(Entry[] attrSets) - throws RemoteException - { - gate(); - delegate.addLookupAttributes(attrSets); - } - - public void modifyLookupAttributes(Entry[] attrSetTemplates, - Entry[] attrSets) - throws RemoteException - { - gate(); - delegate.modifyLookupAttributes(attrSetTemplates, attrSets); - } - - public String[] getLookupGroups() throws RemoteException { - gate(); - return delegate.getLookupGroups(); - } - - public void addLookupGroups(String[] groups) throws RemoteException { - gate(); - delegate.addLookupGroups(groups); - } - - public void removeLookupGroups(String[] groups) throws RemoteException { - gate(); - delegate.removeLookupGroups(groups); - } - - public void setLookupGroups(String[] groups) throws RemoteException { - gate(); - delegate.setLookupGroups(groups); - } - - public LookupLocator[] getLookupLocators() throws RemoteException { - gate(); - return delegate.getLookupLocators(); - } - - public void addLookupLocators(LookupLocator[] locators) - throws RemoteException - { - gate(); - delegate.addLookupLocators(locators); - } - - public void removeLookupLocators(LookupLocator[] locators) - throws RemoteException - { - gate(); - delegate.removeLookupLocators(locators); - } - - public void setLookupLocators(LookupLocator[] locators) - throws RemoteException - { - gate(); - delegate.setLookupLocators(locators); - } - - public Object getProxy() { - // don't need to block or die on this one. - return delegate.getProxy(); - } - - public TrustVerifier getProxyVerifier() throws RemoteException { - gate(); - return delegate.getProxyVerifier(); - } - - public void start() throws IOException, ConfigurationException, LoginException { - delegate.start(); - } -} +/* + * 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.outrigger; + +import java.util.Map; +import java.io.IOException; +import java.rmi.Remote; +import java.rmi.MarshalledObject; +import java.rmi.RemoteException; +import java.rmi.activation.ActivationID; +import java.rmi.activation.ActivationException; +import javax.security.auth.login.LoginException; + +import net.jini.core.discovery.LookupLocator; +import net.jini.core.entry.Entry; +import net.jini.core.event.EventRegistration; +import net.jini.core.event.RemoteEventListener; +import net.jini.core.transaction.Transaction; +import net.jini.core.transaction.TransactionException; +import net.jini.core.transaction.UnknownTransactionException; +import net.jini.core.transaction.server.TransactionManager; +import net.jini.core.lease.Lease; +import net.jini.core.lease.LeaseDeniedException; +import net.jini.core.lease.UnknownLeaseException; +import net.jini.export.ProxyAccessor; +import net.jini.space.JavaSpace; +import net.jini.space.InternalSpaceException; + +import net.jini.security.TrustVerifier; +import net.jini.security.proxytrust.ServerProxyTrust; +import net.jini.config.ConfigurationException; +import net.jini.id.Uuid; + +import org.apache.river.start.lifecycle.LifeCycle; +import org.apache.river.api.util.Startable; +import org.apache.river.outrigger.proxy.EntryRep; +import org.apache.river.outrigger.proxy.OutriggerServer; +import org.apache.river.outrigger.proxy.OutriggerServer.QueryCookie; +import org.apache.river.outrigger.proxy.MatchSetData; + + + + +/** + * For various reasons there is code that we would like + * to run before every incoming remote call. To accomplish + * this we wrap the server in an object that will run + * the common code and then delegate to the server to + * do the actual work. This is a base class for these + * wrappers. + * + * @author Sun Microsystems, Inc. + * @since 2.0 + */ +class OutriggerServerWrapper + implements OutriggerServer, ServerProxyTrust, ProxyAccessor, Startable +{ + /** The object being delegated to */ + private final OutriggerServerImpl delegate; + + /** + * If <code>false</code>, hold calls until it becomes + * <code>true</code> + */ + private boolean allowCalls; + + /** + * If non-null cause incoming calls to immediately throw this + * exception. Takes presidents over <code>holdCalls</code>. This + * field is only set to an <code>Error</code>, + * <code>RemoteException</code>, or <code>RuntimeException</code> + * and thus can be thrown by an of <code>OutriggerServer</code>'s + * methods. + */ + private Throwable failCallsWith; + + /** + * Create an <code>OutriggerServerWrapper</code> that + * will delegate to a non-activatable <code>OutriggerServerImpl</code> + * created with the specified configuration and wrapped by + * <code>this</code>. + * @param configArgs set of strings to be used to obtain a + * <code>Configuration</code>. + * @param lifeCycle the object to notify when this + * service is destroyed. + * @param persistent If <code>true</code> will throw an + * <code>ConfigurationException</code> + * if there is no persistence directory or + * store specified in the configuration. + * @throws IOException if there is problem exporting the server. + * @throws ConfigurationException if the <code>Configuration</code> is + * malformed. + * @throws LoginException if the <code>loginContext</code> specified + * in the configuration is non-null and throws + * an exception when login is attempted. + */ + OutriggerServerWrapper(String[] configArgs, LifeCycle lifeCycle, + boolean persistent) + throws IOException, ConfigurationException, LoginException + { + try { + delegate = new OutriggerServerImpl(null, lifeCycle, configArgs, + persistent, this); + } catch (ActivationException e) { + throw new AssertionError(e); + } + } + + /** + * Create an <code>OutriggerServerWrapper</code> that + * will delegate to an <code>OutriggerServerImpl</code> + * created with the specified argument and wrapped by <code>this</code>. + * @param activationID of the server, must not be <code>null</code>. + * @param configArgs set of strings to be used to obtain a + * <code>Configuration</code>. + * @throws IOException if there is problem recovering data + * from disk, exporting the server, or unpacking + * <code>data</code>. + * @throws ConfigurationException if the <code>Configuration</code> is + * malformed. + * @throws ActivationException if activatable and there + * is a problem getting a reference to the activation system. + * @throws LoginException if the <code>loginContext</code> specified + * in the configuration is non-null and throws + * an exception when login is attempted. + * @throws NullPointerException if <code>activationID</code> + * is <code>null</code>. + */ + OutriggerServerWrapper(ActivationID activationID, String[] configArgs) + throws IOException, ConfigurationException, LoginException, + ActivationException + { + if (activationID == null) + throw new NullPointerException("activationID must be non-null"); + delegate = new OutriggerServerImpl(activationID, null, configArgs, + true, this); + } + + /** + * Cause incoming calls to block until further notice. + */ + synchronized void holdCalls() { + failCallsWith = null; + allowCalls = false; + notifyAll(); + } + + /** + * Cause in new or blocked calls to fail with + * the specified exception. + * @throws IllegalArgumentException if <code>t</code> + * is not an <code>Error</code>, <code>RemoteException</code>, + * or <code>RuntimeException</code>. + * @throws NullPointerException if <code>t</code> is <code>null</code>. + */ + synchronized void rejectCalls(Throwable t) { + if (t == null) + throw new NullPointerException("Throwable must not be null"); + + if (!((t instanceof Error) || + (t instanceof RuntimeException) || + (t instanceof RemoteException))) + throw new IllegalArgumentException("t must be an exception " + + "that can be thrown from any of OutriggerServer's methods"); + + failCallsWith = t; + allowCalls = true; + notifyAll(); + } + + /** + * Allow incoming calls. + */ + synchronized void allowCalls() { + failCallsWith = null; + allowCalls = true; + notifyAll(); + } + + /** + * Block until calls are allowed, or until calls + * are to be rejected. + * @throws RemoteException If calls are being rejected + * with <code>RemoteException</code>s. + * @throws RuntimeException If calls are being rejected + * with <code>RuntimeException</code>s. + * @throws Error If calls are being rejected + * with <code>Error</code>s. + */ + private synchronized void gate() throws RemoteException { + while (!allowCalls || failCallsWith != null) { + if (failCallsWith != null) { + if (failCallsWith instanceof RemoteException) + throw (RemoteException)failCallsWith; + else if (failCallsWith instanceof Error) + throw (Error)failCallsWith; + else if (failCallsWith instanceof RuntimeException) + throw (RuntimeException)failCallsWith; + else + throw new AssertionError("Wrapper trying to " + + "throw " + failCallsWith); + } + + if (!allowCalls) { + try { + wait(); + } catch (InterruptedException e) { + throw new + InternalSpaceException("gate method interrupted"); + } + } + } + } + + + public long[] write(EntryRep entry, Transaction txn, long lease) + throws TransactionException, RemoteException + { + gate(); + return delegate.write(entry, txn, lease); + } + + public Object read(EntryRep tmpl, Transaction txn, long timeout, + QueryCookie cookie) + throws TransactionException, RemoteException, InterruptedException + { + gate(); + return delegate.read(tmpl, txn, timeout, cookie); + } + + public Object readIfExists(EntryRep tmpl, Transaction txn, long timeout, + QueryCookie cookie) + throws TransactionException, RemoteException, InterruptedException + { + gate(); + return delegate.readIfExists(tmpl, txn, timeout, cookie); + } + + public Object take(EntryRep tmpl, Transaction txn, long timeout, + QueryCookie cookie) + throws TransactionException, RemoteException, InterruptedException + { + gate(); + return delegate.take(tmpl, txn, timeout, cookie); + } + + public Object takeIfExists(EntryRep tmpl, Transaction txn, long timeout, + QueryCookie cookie) + throws TransactionException, RemoteException, InterruptedException + { + gate(); + return delegate.takeIfExists(tmpl, txn, timeout, cookie); + } + + public EventRegistration + notify(EntryRep tmpl, Transaction txn, RemoteEventListener listener, + long lease, MarshalledObject handback) + throws TransactionException, RemoteException + { + gate(); + return delegate.notify(tmpl, txn, listener, lease, handback); + } + + public EventRegistration registerForAvailabilityEvent(EntryRep[] tmpls, + Transaction txn, boolean visibilityOnly, RemoteEventListener listener, + long leaseTime, MarshalledObject handback) + throws TransactionException, RemoteException + { + gate(); + return delegate.registerForAvailabilityEvent(tmpls, txn, visibilityOnly, + listener, leaseTime, handback); + } + + public long[] write(EntryRep[] entries, Transaction txn, long[] leaseTimes) + throws TransactionException, RemoteException + { + gate(); + return delegate.write(entries, txn, leaseTimes); + } + + public Object take(EntryRep[] tmpls, Transaction tr, long timeout, + int limit, QueryCookie cookie) + throws TransactionException, RemoteException + { + gate(); + return delegate.take(tmpls, tr, timeout, limit, cookie); + } + + public MatchSetData contents(EntryRep[] tmpls, Transaction tr, + long leaseTime, long limit) + throws TransactionException, RemoteException + { + gate(); + return delegate.contents(tmpls, tr, leaseTime, limit); + } + + public EntryRep[] nextBatch(Uuid contentsQueryUuid, Uuid entryUuid) + throws RemoteException + { + gate(); + return delegate.nextBatch(contentsQueryUuid, entryUuid); + } + + public long renew(Uuid cookie, long extension) + throws LeaseDeniedException, UnknownLeaseException, RemoteException + { + gate(); + return delegate.renew(cookie, extension); + } + + public void cancel(Uuid cookie) + throws UnknownLeaseException, RemoteException + { + gate(); + delegate.cancel(cookie); + } + + public Object getAdmin() throws RemoteException { + gate(); + return delegate.getAdmin(); + } + + public int prepare(TransactionManager mgr, long id) + throws UnknownTransactionException, RemoteException + { + gate(); + return delegate.prepare(mgr, id); + } + + public void commit(TransactionManager mgr, long id) + throws UnknownTransactionException, RemoteException + { + gate(); + delegate.commit(mgr, id); + } + + public void abort(TransactionManager mgr, long id) + throws UnknownTransactionException, RemoteException + { + gate(); + delegate.abort(mgr, id); + } + + public int prepareAndCommit(TransactionManager mgr, long id) + throws UnknownTransactionException, RemoteException + { + gate(); + return delegate.prepareAndCommit(mgr, id); + } + + public RenewResults renewAll(Uuid[] cookies, long[] durations) + throws RemoteException + { + gate(); + return delegate.renewAll(cookies, durations); + } + + public Map cancelAll(Uuid[] cookies) throws RemoteException { + gate(); + return delegate.cancelAll(cookies); + } + + public Object getServiceProxy() throws RemoteException { + gate(); + return delegate.getServiceProxy(); + } + + public JavaSpace space() throws RemoteException { + gate(); + return delegate.space(); + } + + public Uuid contents(EntryRep tmpl, Transaction txn) + throws TransactionException, RemoteException + { + gate(); + return delegate.contents(tmpl, txn); + } + + public EntryRep[] nextReps(Uuid iterationUuid, int max, + Uuid entryUuid) + throws RemoteException + { + gate(); + return delegate.nextReps(iterationUuid, max, entryUuid); + } + + public void delete(Uuid iterationUuid, Uuid entryUuid) + throws RemoteException + { + gate(); + delegate.delete(iterationUuid, entryUuid); + } + + public void close(Uuid iterationUuid) throws RemoteException { + gate(); + delegate.close(iterationUuid); + } + + public void destroy() throws RemoteException { + gate(); + delegate.destroy(); + } + + public Entry[] getLookupAttributes() throws RemoteException { + gate(); + return delegate.getLookupAttributes(); + } + + public void addLookupAttributes(Entry[] attrSets) + throws RemoteException + { + gate(); + delegate.addLookupAttributes(attrSets); + } + + public void modifyLookupAttributes(Entry[] attrSetTemplates, + Entry[] attrSets) + throws RemoteException + { + gate(); + delegate.modifyLookupAttributes(attrSetTemplates, attrSets); + } + + public String[] getLookupGroups() throws RemoteException { + gate(); + return delegate.getLookupGroups(); + } + + public void addLookupGroups(String[] groups) throws RemoteException { + gate(); + delegate.addLookupGroups(groups); + } + + public void removeLookupGroups(String[] groups) throws RemoteException { + gate(); + delegate.removeLookupGroups(groups); + } + + public void setLookupGroups(String[] groups) throws RemoteException { + gate(); + delegate.setLookupGroups(groups); + } + + public LookupLocator[] getLookupLocators() throws RemoteException { + gate(); + return delegate.getLookupLocators(); + } + + public void addLookupLocators(LookupLocator[] locators) + throws RemoteException + { + gate(); + delegate.addLookupLocators(locators); + } + + public void removeLookupLocators(LookupLocator[] locators) + throws RemoteException + { + gate(); + delegate.removeLookupLocators(locators); + } + + public void setLookupLocators(LookupLocator[] locators) + throws RemoteException + { + gate(); + delegate.setLookupLocators(locators); + } + + public Object getProxy() { + // don't need to block or die on this one. + return delegate.getProxy(); + } + + public TrustVerifier getProxyVerifier() throws RemoteException { + gate(); + return delegate.getProxyVerifier(); + } + + public void start() throws IOException, ConfigurationException, LoginException { + delegate.start(); + } +}
Modified: river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/PersistentOutriggerImpl.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/PersistentOutriggerImpl.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/PersistentOutriggerImpl.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/PersistentOutriggerImpl.java Sun Jul 5 11:41:39 2020 @@ -1,92 +1,95 @@ -/* - * 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.outrigger; - -import java.io.IOException; -import java.rmi.Remote; -import java.rmi.MarshalledObject; -import java.rmi.activation.ActivationID; -import java.rmi.activation.ActivationException; -import javax.security.auth.login.LoginException; -import net.jini.config.ConfigurationException; -import org.apache.river.start.LifeCycle; -import net.jini.io.MarshalledInstance; - -/** - * <code>OutriggerServerWrapper</code> subclass for - * persistent servers. - * - * @author Sun Microsystems, Inc. - * @since 2.0 - */ -class PersistentOutriggerImpl extends OutriggerServerWrapper { - /** - * Create a new incarnation of an activatable - * <code>OutriggerServerImpl</code> server. - * @param activationID of the server, may be <code>null</code>. - * @param data an array of <code>String</code>s (packaged in - * a marshalled object) that will be used - * to obtain a <code>Configuration</code>. - * @throws IOException if there is problem recovering data - * from disk, exporting the server, or unpacking - * <code>data</code>. - * @throws ClassCastException if the value of <code>data.get()</code> - * is not an array of <code>String</code>s. - * @throws ConfigurationException if the <code>Configuration</code> is - * malformed. - * @throws ActivationException if activatable and there - * is a problem getting a reference to the activation system. - * @throws LoginException if the <code>loginContext</code> specified - * in the configuration is non-null and throws - * an exception when login is attempted. - * @throws ClassNotFoundException if the classes of the objects - * encapsulated inside <code>data</code> can not be found. - */ - PersistentOutriggerImpl(ActivationID activationID, - MarshalledObject data) - throws IOException, ConfigurationException, LoginException, - ActivationException, ClassNotFoundException - { - super(activationID, (String[]) new MarshalledInstance(data).get(false)); - allowCalls(); - } - - /** - * Create a new non-activatable, persistent space. - * The space will be implemented by a new - * <code>OutriggerServerImpl()</code> server instance. - * @param configArgs set of strings to be used to obtain a - * <code>Configuration</code>. - * @param lifeCycle the object to notify when this - * service is destroyed. - * @throws IOException if there is problem recovering data - * from disk or exporting the server for the space. - * @throws ConfigurationException if the configuration is - * malformed. - * @throws LoginException if the <code>loginContext</code> specified - * in the configuration is non-null and throws - * an exception when login is attempted. - */ - PersistentOutriggerImpl(String[] configArgs, LifeCycle lifeCycle) - throws IOException, ConfigurationException, LoginException - { - super(configArgs, lifeCycle, true); - allowCalls(); - } -} - +/* + * 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.outrigger; + +import java.io.IOException; +import java.rmi.Remote; +import java.rmi.MarshalledObject; +import java.rmi.activation.ActivationID; +import java.rmi.activation.ActivationException; +import javax.security.auth.login.LoginException; +import net.jini.config.ConfigurationException; +import org.apache.river.start.lifecycle.LifeCycle; +import net.jini.io.MarshalledInstance; + + + + +/** + * <code>OutriggerServerWrapper</code> subclass for + * persistent servers. + * + * @author Sun Microsystems, Inc. + * @since 2.0 + */ +class PersistentOutriggerImpl extends OutriggerServerWrapper { + /** + * Create a new incarnation of an activatable + * <code>OutriggerServerImpl</code> server. + * @param activationID of the server, may be <code>null</code>. + * @param data an array of <code>String</code>s (packaged in + * a marshalled object) that will be used + * to obtain a <code>Configuration</code>. + * @throws IOException if there is problem recovering data + * from disk, exporting the server, or unpacking + * <code>data</code>. + * @throws ClassCastException if the value of <code>data.get()</code> + * is not an array of <code>String</code>s. + * @throws ConfigurationException if the <code>Configuration</code> is + * malformed. + * @throws ActivationException if activatable and there + * is a problem getting a reference to the activation system. + * @throws LoginException if the <code>loginContext</code> specified + * in the configuration is non-null and throws + * an exception when login is attempted. + * @throws ClassNotFoundException if the classes of the objects + * encapsulated inside <code>data</code> can not be found. + */ + PersistentOutriggerImpl(ActivationID activationID, + MarshalledObject data) + throws IOException, ConfigurationException, LoginException, + ActivationException, ClassNotFoundException + { + super(activationID, (String[]) new MarshalledInstance(data).get(false)); + allowCalls(); + } + + /** + * Create a new non-activatable, persistent space. + * The space will be implemented by a new + * <code>OutriggerServerImpl()</code> server instance. + * @param configArgs set of strings to be used to obtain a + * <code>Configuration</code>. + * @param lifeCycle the object to notify when this + * service is destroyed. + * @throws IOException if there is problem recovering data + * from disk or exporting the server for the space. + * @throws ConfigurationException if the configuration is + * malformed. + * @throws LoginException if the <code>loginContext</code> specified + * in the configuration is non-null and throws + * an exception when login is attempted. + */ + PersistentOutriggerImpl(String[] configArgs, LifeCycle lifeCycle) + throws IOException, ConfigurationException, LoginException + { + super(configArgs, lifeCycle, true); + allowCalls(); + } +} + Modified: river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/ReadIfExistsWatcher.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/ReadIfExistsWatcher.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/ReadIfExistsWatcher.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/ReadIfExistsWatcher.java Sun Jul 5 11:41:39 2020 @@ -1,216 +1,217 @@ -/* - * 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.outrigger; - -import java.util.Set; -import net.jini.id.Uuid; - -/** - * Subclass of <code>QueryWatcher</code> for non-transactional if - * exists reads. Resolves with the first matching - * transition where the transaction is <code>null</code> and the entry - * is visible (the entry's current state is ignored) or if - * the locked entry set goes empty. - */ -class ReadIfExistsWatcher extends SingletonQueryWatcher - implements IfExistsWatcher -{ - /** - * The set of entries that would match but are currently - * unavailable (e.g. they are locked). We only keep - * the ids, not the entries themselves. - */ - private final Set<Uuid> lockedEntries; - - /** - * Set <code>true</code> once the query thread is - * done processing the backlog. Once this is - * <code>true</code> it is ok to resolve if - * <code>lockedEntries</code> is empty. - */ - private boolean backlogFinished = false; - - /** - * Create a new <code>ReadIfExistsWatcher</code>. - * @param expiration the initial expiration time - * for this <code>TransitionWatcher</code> in - * milliseconds since the beginning of the epoch. - * @param timestamp the value that is used - * to sort <code>TransitionWatcher</code>s. - * @param startOrdinal the highest ordinal associated - * with operations that are considered to have occurred - * before the operation associated with this watcher. - * @param lockedEntries Set of entries (by their IDs) - * that match but are unavailable. Must be non-empty. - * Keeps a reference to this object. - * @throws NullPointerException if <code>lockedEntries</code> is - * <code>null</code>. - */ - ReadIfExistsWatcher(long expiration, long timestamp, long startOrdinal, - Set<Uuid> lockedEntries) - { - super(expiration, timestamp, startOrdinal); - - if (lockedEntries == null) - throw new NullPointerException("lockedEntries must be non-null"); - - this.lockedEntries = lockedEntries; - } - - boolean isInterested(EntryTransition transition, long ordinal) { - /* If we are unresolved pretty much all transitions are - * interesting because we may need to update - * lockedEntries. The only exception is read locks being - * resolved. It is important that transitions triggered by the - * release of read locks get filtered out - otherwise process - * could end up adding and removing elements to lockedEntries - * when it shouldn't. - * - * Note, !isResolved() without the lock will result only in - * false positives, not false negatives - it will only - * cause isInterested() to return false if we are resolved, - * we may still return true if we are resolved though. - */ - - if (!transition.isVisible() && transition.isAvailable()) { - /* must be a transition triggered by a read lock release, - * wont change anything so ignore it. - */ - return false; - } - - return (ordinal>startOrdinal) && !isResolved(); - } - - synchronized void process(EntryTransition transition, long now) { - if (isResolved()) - return; // Already done. - - final EntryRep rep = transition.getHandle().rep(); - final boolean isVisible = transition.isVisible(); - - /* If the entry was visible at one time to the null - * transaction we can just resolve. - */ - if (isVisible && (transition.getTxn() == null)) { - resolve(transition.getHandle(), null); - } else if (isVisible) { // && getTxn() != null - /* If we are here transition.getTxn() must be != null - * and the entry was visible, implying that it was an entry - * written under a transaction and is interesting to - * us, but not yet visible. We need to add it lockedEntries - * even if has been removed since it could have gotten - * replaced before it was removed. If we did not - * add it we would be acting on the future. - */ - lockedEntries.add(rep.id()); - } else { - /* Must not be visible (and becaues of the test in - * isInteresting can't be available either - that is - * transition can't just be the release of a read lock), - * transition must mark the resolution of the transaction - * in such away that the entry has been removed, remove it - * from the set and see if that makes the set empty. - */ - lockedEntries.remove(rep.id()); - if (backlogFinished && lockedEntries.isEmpty()) - resolve(null, null); - } - } - - synchronized boolean catchUp(EntryTransition transition, long now) { - if (isResolved()) - return true; // Already done. - - final EntryHandle handle = transition.getHandle(); - final EntryRep rep = handle.rep(); - final boolean isVisible = transition.isVisible(); - - /* Was this the resolution of a read lock? if so ignore */ - if (!isVisible && transition.isAvailable()) - return false; - - /* If the entry was visible at one time to the null - * transaction we can just resolve. - */ - if (isVisible && (transition.getTxn() == null)) { - resolve(handle, null); - return true; - } - - if (isVisible) { // && getTxn() != null - /* If we are here transition.getTxn() must be != null and - * the entry is/was visible to someone, implying that it - * was an entry written under a transaction and is - * interesting to us, but not yet visible to us. We only - * add if it has not already been removed. It might have - * gotten replaced before removal, but since we won't let - * this query get resolved with a definitive null before - * we get past the point in the journal where it was - * removed it is ok to never put it in (and if we did put - * it in it might never get removed since process() may - * have already processed the removal). We don't need to - * check to see it the entry has been provisionally - * removed since if has been provisional removal does not - * put in entries in the journal and if it is - * provisionally removed it has not yet been removed so - * the remove recored has not yet been created (must less - * processed). - */ - synchronized (handle) { - if (!handle.removed()) { - lockedEntries.add(rep.id()); - } - } - - // Either way, still not resolved. - return false; - } - - /* Must not be visible (and because of the first test can't be - * available either - that is transition can't just be the - * release of a read lock), transition must mark the - * resolution of the transaction in such away that the entry - * has been removed, remove it from the set (don't need to - * check for empty because we haven't gotten to the point - * where we can resolve with a definitive null.) - */ - lockedEntries.remove(rep.id()); - return false; - } - - /** - * Once the backlog is complete we can resolve if - * lockedEntries is/becomes empty. - */ - public synchronized void caughtUp() { - backlogFinished = true; - - if (isResolved()) - return; // Don't much mater. - - if (lockedEntries.isEmpty()) - resolve(null, null); - } - - public synchronized boolean isLockedEntrySetEmpty() { - if (!isResolved()) - throw new IllegalStateException("Query not yet resolved"); - return lockedEntries.isEmpty(); - } -} +/* + * 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.outrigger; + +import java.util.Set; +import net.jini.id.Uuid; +import org.apache.river.outrigger.proxy.EntryRep; + +/** + * Subclass of <code>QueryWatcher</code> for non-transactional if + * exists reads. Resolves with the first matching + * transition where the transaction is <code>null</code> and the entry + * is visible (the entry's current state is ignored) or if + * the locked entry set goes empty. + */ +class ReadIfExistsWatcher extends SingletonQueryWatcher + implements IfExistsWatcher +{ + /** + * The set of entries that would match but are currently + * unavailable (e.g. they are locked). We only keep + * the ids, not the entries themselves. + */ + private final Set<Uuid> lockedEntries; + + /** + * Set <code>true</code> once the query thread is + * done processing the backlog. Once this is + * <code>true</code> it is ok to resolve if + * <code>lockedEntries</code> is empty. + */ + private boolean backlogFinished = false; + + /** + * Create a new <code>ReadIfExistsWatcher</code>. + * @param expiration the initial expiration time + * for this <code>TransitionWatcher</code> in + * milliseconds since the beginning of the epoch. + * @param timestamp the value that is used + * to sort <code>TransitionWatcher</code>s. + * @param startOrdinal the highest ordinal associated + * with operations that are considered to have occurred + * before the operation associated with this watcher. + * @param lockedEntries Set of entries (by their IDs) + * that match but are unavailable. Must be non-empty. + * Keeps a reference to this object. + * @throws NullPointerException if <code>lockedEntries</code> is + * <code>null</code>. + */ + ReadIfExistsWatcher(long expiration, long timestamp, long startOrdinal, + Set<Uuid> lockedEntries) + { + super(expiration, timestamp, startOrdinal); + + if (lockedEntries == null) + throw new NullPointerException("lockedEntries must be non-null"); + + this.lockedEntries = lockedEntries; + } + + boolean isInterested(EntryTransition transition, long ordinal) { + /* If we are unresolved pretty much all transitions are + * interesting because we may need to update + * lockedEntries. The only exception is read locks being + * resolved. It is important that transitions triggered by the + * release of read locks get filtered out - otherwise process + * could end up adding and removing elements to lockedEntries + * when it shouldn't. + * + * Note, !isResolved() without the lock will result only in + * false positives, not false negatives - it will only + * cause isInterested() to return false if we are resolved, + * we may still return true if we are resolved though. + */ + + if (!transition.isVisible() && transition.isAvailable()) { + /* must be a transition triggered by a read lock release, + * wont change anything so ignore it. + */ + return false; + } + + return (ordinal>startOrdinal) && !isResolved(); + } + + synchronized void process(EntryTransition transition, long now) { + if (isResolved()) + return; // Already done. + + final EntryRep rep = transition.getHandle().rep(); + final boolean isVisible = transition.isVisible(); + + /* If the entry was visible at one time to the null + * transaction we can just resolve. + */ + if (isVisible && (transition.getTxn() == null)) { + resolve(transition.getHandle(), null); + } else if (isVisible) { // && getTxn() != null + /* If we are here transition.getTxn() must be != null + * and the entry was visible, implying that it was an entry + * written under a transaction and is interesting to + * us, but not yet visible. We need to add it lockedEntries + * even if has been removed since it could have gotten + * replaced before it was removed. If we did not + * add it we would be acting on the future. + */ + lockedEntries.add(rep.id()); + } else { + /* Must not be visible (and becaues of the test in + * isInteresting can't be available either - that is + * transition can't just be the release of a read lock), + * transition must mark the resolution of the transaction + * in such away that the entry has been removed, remove it + * from the set and see if that makes the set empty. + */ + lockedEntries.remove(rep.id()); + if (backlogFinished && lockedEntries.isEmpty()) + resolve(null, null); + } + } + + synchronized boolean catchUp(EntryTransition transition, long now) { + if (isResolved()) + return true; // Already done. + + final EntryHandle handle = transition.getHandle(); + final EntryRep rep = handle.rep(); + final boolean isVisible = transition.isVisible(); + + /* Was this the resolution of a read lock? if so ignore */ + if (!isVisible && transition.isAvailable()) + return false; + + /* If the entry was visible at one time to the null + * transaction we can just resolve. + */ + if (isVisible && (transition.getTxn() == null)) { + resolve(handle, null); + return true; + } + + if (isVisible) { // && getTxn() != null + /* If we are here transition.getTxn() must be != null and + * the entry is/was visible to someone, implying that it + * was an entry written under a transaction and is + * interesting to us, but not yet visible to us. We only + * add if it has not already been removed. It might have + * gotten replaced before removal, but since we won't let + * this query get resolved with a definitive null before + * we get past the point in the journal where it was + * removed it is ok to never put it in (and if we did put + * it in it might never get removed since process() may + * have already processed the removal). We don't need to + * check to see it the entry has been provisionally + * removed since if has been provisional removal does not + * put in entries in the journal and if it is + * provisionally removed it has not yet been removed so + * the remove recored has not yet been created (must less + * processed). + */ + synchronized (handle) { + if (!handle.removed()) { + lockedEntries.add(rep.id()); + } + } + + // Either way, still not resolved. + return false; + } + + /* Must not be visible (and because of the first test can't be + * available either - that is transition can't just be the + * release of a read lock), transition must mark the + * resolution of the transaction in such away that the entry + * has been removed, remove it from the set (don't need to + * check for empty because we haven't gotten to the point + * where we can resolve with a definitive null.) + */ + lockedEntries.remove(rep.id()); + return false; + } + + /** + * Once the backlog is complete we can resolve if + * lockedEntries is/becomes empty. + */ + public synchronized void caughtUp() { + backlogFinished = true; + + if (isResolved()) + return; // Don't much mater. + + if (lockedEntries.isEmpty()) + resolve(null, null); + } + + public synchronized boolean isLockedEntrySetEmpty() { + if (!isResolved()) + throw new IllegalStateException("Query not yet resolved"); + return lockedEntries.isEmpty(); + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/RepEnum.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/RepEnum.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/RepEnum.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/RepEnum.java Sun Jul 5 11:41:39 2020 @@ -1,36 +1,38 @@ -/* - * 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.outrigger; - -/** - * An internal interface for enumerating through <code>EntryRep</code> - * objects inside a JavaSpace server. - * - * @author Sun Microsystems, Inc. - * - * @see EntryHolder#contents - */ -// * @see OutriggerServerImpl#AllReps -interface RepEnum { - /** - * Return the next <code>EntryRep</code> object, or <code>null</code> - * if there is none. Repeated calls at the end simply continue to return - * <code>null</code>. - */ - EntryRep nextRep(); -} +/* + * 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.outrigger; + +import org.apache.river.outrigger.proxy.EntryRep; + +/** + * An internal interface for enumerating through <code>EntryRep</code> + * objects inside a JavaSpace server. + * + * @author Sun Microsystems, Inc. + * + * @see EntryHolder#contents + */ +// * @see OutriggerServerImpl#AllReps +interface RepEnum { + /** + * Return the next <code>EntryRep</code> object, or <code>null</code> + * if there is none. Repeated calls at the end simply continue to return + * <code>null</code>. + */ + EntryRep nextRep(); +} Modified: river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StorableAvailabilityWatcher.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StorableAvailabilityWatcher.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StorableAvailabilityWatcher.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StorableAvailabilityWatcher.java Sun Jul 5 11:41:39 2020 @@ -1,180 +1,183 @@ -/* - * 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.outrigger; - -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.IOException; -import java.io.StreamCorruptedException; -import java.rmi.MarshalledObject; -import net.jini.core.event.RemoteEventListener; -import net.jini.id.Uuid; -import net.jini.id.UuidFactory; -import net.jini.security.ProxyPreparer; - -/** - * Subclass of <code>AvailabilityRegistrationWatcher</code> for - * non-transactional persistent availability/visibility event - * registrations. - */ -class StorableAvailabilityWatcher extends AvailabilityRegistrationWatcher - implements StorableResource<StorableAvailabilityWatcher> -{ - /** The listener that should be notified of matches */ - private StorableReference listener; - - /** - * Used during log recovery to create a mostly empty - * <code>StorableAvailabilityWatcher</code>. - * <p> - * Note, we set the time stamp and tie-breaker here instead of - * getting them from the log. This means they will be inconstant - * with their value from the last VM we were in, but since they - * never leak out and events are read-only anyway this should not - * be a problem (this also allows us to keep the tie-breaker and - * time stamp in final fields). - * - * @param timestamp the value that is used - * to sort <code>TransitionWatcher</code>s. - * @param startOrdinal the highest ordinal associated - * with operations that are considered to have occurred - * before the operation associated with this watcher. - * @param currentSeqNum Sequence number to start with. - * @throws NullPointerException if the <code>notifier</code> - * argument is null. - */ - StorableAvailabilityWatcher(long timestamp, long startOrdinal, - long currentSeqNum) - { - super(timestamp, startOrdinal, currentSeqNum); - } - - /** - * Create a new <code>StorableAvailabilityWatcher</code>. - * @param timestamp the value that is used - * to sort <code>TransitionWatcher</code>s. - * @param startOrdinal the highest ordinal associated - * with operations that are considered to have occurred - * before the operation associated with this watcher. - * @param cookie The unique identifier associated - * with this watcher. Must not be <code>null</code>. - * @param visibilityOnly pass <code>true</code> if client - * only wants visibility events - * @param handback The handback object that - * should be sent along with event - * notifications to the the listener. - * @param eventID The event ID for event type - * represented by this object. - * @param listener The object to notify of - * matches. - * @throws NullPointerException if the <code>cookie</code>, - * or <code>listener</code> arguments are <code>null</code>. - */ - StorableAvailabilityWatcher(long timestamp, long startOrdinal, Uuid cookie, - boolean visibilityOnly, MarshalledObject handback, long eventID, - RemoteEventListener listener) - { - super(timestamp, startOrdinal, cookie, visibilityOnly, handback, - eventID); - - if (listener == null) - throw new NullPointerException("listener must be non-null"); - this.listener = new StorableReference(listener); - } - - boolean isInterested(EntryTransition transition, long ordinal) { - if (ordinal <= startOrdinal) - return false; - - if (transition.getTxn() != null) - return false; - - if (!transition.isAvailable()) - return false; - - if (visibilityOnly && !transition.isVisible()) - return false; - - if (transition.hasProcessed(this)) - return false; - - transition.processedBy(this); - return true; - } - - RemoteEventListener getListener(ProxyPreparer preparer) - throws ClassNotFoundException, IOException - { - StorableReference listen; - synchronized (this){ - listen = listener; - } - return (RemoteEventListener)listen.get(preparer); - } - - /** - * Overridden by subclasses if there is any cleanup work they need - * to do as part of <code>cancel</code> or - * <code>removeIfExpired</code>. Called after releasing the lock - * on <code>this</code>. Will be called at most once. - * @param server A reference to the owner. - * @param expired <code>true</code> if being called from - * <code>removeIfExpired</code> and false otherwise. - */ - void cleanup(OutriggerServerImpl server, boolean expired) { - if (expired) - server.scheduleCancelOp(cookie); - else - server.cancelOp(cookie, false); - } - - /** - * Store the persistent fields - */ - public void store(ObjectOutputStream out) throws IOException { - synchronized (this){ - cookie.write(out); - out.writeLong(expiration); - out.writeLong(eventID); - out.writeBoolean(visibilityOnly); - out.writeObject(handback); - out.writeObject(listener); - } - } - - /** - * Restore the persistent fields - */ - public StorableAvailabilityWatcher restore(ObjectInputStream in) - throws IOException, ClassNotFoundException - { - synchronized (this){ - cookie = UuidFactory.read(in); - expiration = in.readLong(); - eventID = in.readLong(); - visibilityOnly = in.readBoolean(); - handback = (MarshalledObject)in.readObject(); - listener = (StorableReference)in.readObject(); - if (listener == null) - throw new StreamCorruptedException( - "Stream corrupted, should not be null"); - return this; - } - } -} - +/* + * 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.outrigger; + +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.IOException; +import java.io.StreamCorruptedException; +import java.rmi.MarshalledObject; +import net.jini.core.event.RemoteEventListener; +import net.jini.id.Uuid; +import net.jini.id.UuidFactory; +import net.jini.security.ProxyPreparer; +import org.apache.river.outrigger.proxy.StorableResource; + + + +/** + * Subclass of <code>AvailabilityRegistrationWatcher</code> for + * non-transactional persistent availability/visibility event + * registrations. + */ +class StorableAvailabilityWatcher extends AvailabilityRegistrationWatcher + implements StorableResource<StorableAvailabilityWatcher> +{ + /** The listener that should be notified of matches */ + private StorableReference listener; + + /** + * Used during log recovery to create a mostly empty + * <code>StorableAvailabilityWatcher</code>. + * <p> + * Note, we set the time stamp and tie-breaker here instead of + * getting them from the log. This means they will be inconstant + * with their value from the last VM we were in, but since they + * never leak out and events are read-only anyway this should not + * be a problem (this also allows us to keep the tie-breaker and + * time stamp in final fields). + * + * @param timestamp the value that is used + * to sort <code>TransitionWatcher</code>s. + * @param startOrdinal the highest ordinal associated + * with operations that are considered to have occurred + * before the operation associated with this watcher. + * @param currentSeqNum Sequence number to start with. + * @throws NullPointerException if the <code>notifier</code> + * argument is null. + */ + StorableAvailabilityWatcher(long timestamp, long startOrdinal, + long currentSeqNum) + { + super(timestamp, startOrdinal, currentSeqNum); + } + + /** + * Create a new <code>StorableAvailabilityWatcher</code>. + * @param timestamp the value that is used + * to sort <code>TransitionWatcher</code>s. + * @param startOrdinal the highest ordinal associated + * with operations that are considered to have occurred + * before the operation associated with this watcher. + * @param cookie The unique identifier associated + * with this watcher. Must not be <code>null</code>. + * @param visibilityOnly pass <code>true</code> if client + * only wants visibility events + * @param handback The handback object that + * should be sent along with event + * notifications to the the listener. + * @param eventID The event ID for event type + * represented by this object. + * @param listener The object to notify of + * matches. + * @throws NullPointerException if the <code>cookie</code>, + * or <code>listener</code> arguments are <code>null</code>. + */ + StorableAvailabilityWatcher(long timestamp, long startOrdinal, Uuid cookie, + boolean visibilityOnly, MarshalledObject handback, long eventID, + RemoteEventListener listener) + { + super(timestamp, startOrdinal, cookie, visibilityOnly, handback, + eventID); + + if (listener == null) + throw new NullPointerException("listener must be non-null"); + this.listener = new StorableReference(listener); + } + + boolean isInterested(EntryTransition transition, long ordinal) { + if (ordinal <= startOrdinal) + return false; + + if (transition.getTxn() != null) + return false; + + if (!transition.isAvailable()) + return false; + + if (visibilityOnly && !transition.isVisible()) + return false; + + if (transition.hasProcessed(this)) + return false; + + transition.processedBy(this); + return true; + } + + RemoteEventListener getListener(ProxyPreparer preparer) + throws ClassNotFoundException, IOException + { + StorableReference listen; + synchronized (this){ + listen = listener; + } + return (RemoteEventListener)listen.get(preparer); + } + + /** + * Overridden by subclasses if there is any cleanup work they need + * to do as part of <code>cancel</code> or + * <code>removeIfExpired</code>. Called after releasing the lock + * on <code>this</code>. Will be called at most once. + * @param server A reference to the owner. + * @param expired <code>true</code> if being called from + * <code>removeIfExpired</code> and false otherwise. + */ + void cleanup(OutriggerServerImpl server, boolean expired) { + if (expired) + server.scheduleCancelOp(cookie); + else + server.cancelOp(cookie, false); + } + + /** + * Store the persistent fields + */ + public void store(ObjectOutputStream out) throws IOException { + synchronized (this){ + cookie.write(out); + out.writeLong(expiration); + out.writeLong(eventID); + out.writeBoolean(visibilityOnly); + out.writeObject(handback); + out.writeObject(listener); + } + } + + /** + * Restore the persistent fields + */ + public StorableAvailabilityWatcher restore(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + synchronized (this){ + cookie = UuidFactory.read(in); + expiration = in.readLong(); + eventID = in.readLong(); + visibilityOnly = in.readBoolean(); + handback = (MarshalledObject)in.readObject(); + listener = (StorableReference)in.readObject(); + if (listener == null) + throw new StreamCorruptedException( + "Stream corrupted, should not be null"); + return this; + } + } +} + Modified: river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StorableEventWatcher.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StorableEventWatcher.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StorableEventWatcher.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StorableEventWatcher.java Sun Jul 5 11:41:39 2020 @@ -28,6 +28,10 @@ import net.jini.id.Uuid; import net.jini.id.UuidFactory; import net.jini.security.ProxyPreparer; +import org.apache.river.outrigger.proxy.StorableResource; + + + /** * Subclass of <code>EventRegistrationWatcher</code> for non-transactional * persistent event registrations. Modified: river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StoredObject.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StoredObject.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StoredObject.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StoredObject.java Sun Jul 5 11:41:39 2020 @@ -1,44 +1,47 @@ -/* - * 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.outrigger; - -import java.io.IOException; - -/** - * Interface for a stored resource. Objects implementing this interface - * are passed into calls to <code>Recover</code> objects. - * - * @param <T> the type of object stored. - * @see Recover - */ -public interface StoredObject<T extends StorableObject<T>> { - - /** - * Restore the state of a <code>StorableObject</code> object. - * - * There are two use cases for this method:<br> - * - * 1. The object passed in is restored with the stored state and the same object returned.<br> - * 2. The object passed in is immutable and a copy with the restored state is returned.<br> - * - * @param object to restore - * @return a restored instance of T - */ - public T restore(T object) - throws IOException, ClassNotFoundException; -} +/* + * 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.outrigger; + +import java.io.IOException; +import org.apache.river.outrigger.proxy.StorableObject; + + + +/** + * Interface for a stored resource. Objects implementing this interface + * are passed into calls to <code>Recover</code> objects. + * + * @param <T> the type of object stored. + * @see Recover + */ +public interface StoredObject<T extends StorableObject<T>> { + + /** + * Restore the state of a <code>StorableObject</code> object. + * + * There are two use cases for this method:<br> + * + * 1. The object passed in is restored with the stored state and the same object returned.<br> + * 2. The object passed in is immutable and a copy with the restored state is returned.<br> + * + * @param object to restore + * @return a restored instance of T + */ + public T restore(T object) + throws IOException, ClassNotFoundException; +} Modified: river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StoredResource.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StoredResource.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StoredResource.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/outrigger/outrigger-service/src/main/java/org/apache/river/outrigger/StoredResource.java Sun Jul 5 11:41:39 2020 @@ -1,47 +1,49 @@ -/* - * 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.outrigger; - -import java.io.IOException; - -/** - * Interface for a stored resource. Objects implementing this interface - * are passed into calls to <code>Recover</code> objects. This objects - * represented by this interface are resources that have expiration - * times (LeasedResource). - * - * @see Recover - */ -public interface StoredResource { - - /** - * Restore the state of a <code>StorableResource</code>. The resource - * to be restored will have its expiration set before this method - * returns. - * - * If this method returned a new StorableResource instead of mutating - * the passed in StorableResource as a side effect, the implementation - * could be thread safe and immutable. - * - * @see LogOps#renewOp - * - * @param obj resource to restore - */ - public void restore(StorableResource obj) - throws IOException, ClassNotFoundException; -} +/* + * 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.outrigger; + +import java.io.IOException; +import org.apache.river.outrigger.proxy.StorableResource; + + +/** + * Interface for a stored resource. Objects implementing this interface + * are passed into calls to <code>Recover</code> objects. This objects + * represented by this interface are resources that have expiration + * times (LeasedResource). + * + * @see Recover + */ +public interface StoredResource { + + /** + * Restore the state of a <code>StorableResource</code>. The resource + * to be restored will have its expiration set before this method + * returns. + * + * If this method returned a new StorableResource instead of mutating + * the passed in StorableResource as a side effect, the implementation + * could be thread safe and immutable. + * + * @see LogOps#renewOp + * + * @param obj resource to restore + */ + public void restore(StorableResource obj) + throws IOException, ClassNotFoundException; +}
