[java-opensaml] branch main updated: Remove unused SingletonFactory interface and impls.

Scott Cantor cantor.2 at osu.edu
Wed Mar 15 12:47:55 UTC 2023


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=7ad0cdad4708cddfbe702a805d0da9d27e19146b

The following commit(s) were added to refs/heads/main by this push:
     new 7ad0cdad4 Remove unused SingletonFactory interface and impls.
7ad0cdad4 is described below

commit 7ad0cdad4708cddfbe702a805d0da9d27e19146b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Mar 15 08:47:52 2023 -0400

    Remove unused SingletonFactory interface and impls.
---
 .../xml/util/AbstractSimpleSingletonFactory.java   |  64 -------
 .../core/xml/util/AbstractSingletonFactory.java    |  82 --------
 .../xml/util/AbstractWrappedSingletonFactory.java  | 206 ---------------------
 .../opensaml/core/xml/util/SingletonFactory.java   |  42 -----
 4 files changed, 394 deletions(-)

diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractSimpleSingletonFactory.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractSimpleSingletonFactory.java
deleted file mode 100644
index f99998f01..000000000
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractSimpleSingletonFactory.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID 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.opensaml.core.xml.util;
-
-import java.util.WeakHashMap;
-
-/**
- * A simple implementation of {@link SingletonFactory}.
- * 
- * <p>
- * A {@link WeakHashMap} is used as the underlying store. This ensures that if the input class 
- * instance become otherwise unused (weakly reachable), the input class instance key used 
- * within the factory will not prevent the input class instance from being garbage-collected,
- * thereby preventing a memory leak.
- * </p>
- * 
- * <p>
- * <strong>NOTE: </strong>If the output class instance holds a strong or soft reference to the input class,
- * do not use this factory.  See instead {@link AbstractWrappedSingletonFactory}. Usage of this
- * class in that scenario will result in a memory leak, as the input class instance will never
- * become weakly reachable and therefore never garbage collected.
- * </p>
- * 
- *
- * @param <Input> the factory input class type
- * @param <Output> the factory output class type
- */
-public abstract class AbstractSimpleSingletonFactory<Input, Output> 
-        extends AbstractSingletonFactory<Input, Output> {
-    
-    /** Storage for the factory. */
-    private WeakHashMap<Input, Output> map;
-    
-    /** Constructor. */
-    public AbstractSimpleSingletonFactory() {
-        map = new WeakHashMap<>();
-    }
-    
-    /** {@inheritDoc} */
-    protected synchronized Output get(final Input input) {
-        return map.get(input);
-    }
-    
-    /** {@inheritDoc} */
-    protected synchronized void put(final Input input, final Output output) {
-        map.put(input, output);
-    }
-    
-}
\ No newline at end of file
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractSingletonFactory.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractSingletonFactory.java
deleted file mode 100644
index 003e2512b..000000000
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractSingletonFactory.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID 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.opensaml.core.xml.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * An abstract Template design pattern implementation of {@link SingletonFactory}.
- *
- * @param <Input> the factory input class type
- * @param <Output> the factory output class type
- */
-public abstract class AbstractSingletonFactory<Input, Output> implements SingletonFactory<Input, Output> {
-    
-    /** Class logger. */
-    private final Logger log = LoggerFactory.getLogger(AbstractSingletonFactory.class);
-    
-    /** {@inheritDoc} */
-    public synchronized Output getInstance(final Input input) {
-        Output output = get(input);
-        if (output != null) {
-            log.trace("Input key mapped to a non-null value, returning output");
-            return output;
-        }
-        log.trace("Input key mapped to a null value");
-        
-        log.trace("Creating new output instance and inserting to factory map");
-        output = createNewInstance(input);
-        if (output == null) {
-            log.error("New output instance was not created");
-            return null;
-         }
-        
-        put(input, output);
-        
-        return output;
-    }
-    
-    /**
-     * Get the output instance currently associated with
-     * the input instance.
-     * 
-     * @param input the input instance key
-     * @return the output instance which corresponds to the input instance,
-     *              or null if not present
-     */
-    protected abstract Output get(Input input);
-    
-    /**
-     * Store the input and output instance association.
-     * 
-     * @param input the input instance key
-     * @param output the output instance value
-     */
-    protected abstract void put(Input input, Output output);
-
-    /**
-     * Create a new instance of the output class based on the input
-     * class instance.
-     * 
-     * @param input the input class instance
-     * @return an output class instance
-     */
-    protected abstract Output createNewInstance(Input input);
-
-}
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractWrappedSingletonFactory.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractWrappedSingletonFactory.java
deleted file mode 100644
index ae92821c5..000000000
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/AbstractWrappedSingletonFactory.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID 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.opensaml.core.xml.util;
-
-import java.lang.ref.WeakReference;
-import java.util.HashSet;
-import java.util.WeakHashMap;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * An implementation of {@link SingletonFactory}, which provides some support for handling
- * cases where the output class instance holds a reference to the input class instance.
- * 
- * <p>
- * A {@link WeakHashMap} is used as the underlying store. This ensures that if the input class
- * instance become otherwise unused (weakly reachable), the input class instance key used
- * within the factory will not prevent the input class from being garbage-collected,
- * thereby preventing a memory leak.
- * </p>
- * 
- * <p>
- * This class differs from {@link AbstractSimpleSingletonFactory} in that output value instances 
- * stored and returned by the factory are also wrapped internally in a {@link WeakReference}.
- * This class should be used in cases where the output class holds a reference to the input 
- * class key, so as not to prevent the described weak reference-based garbage collection 
- * of the input class key, and thereby avoiding a memory leak.
- * </p>
- * 
- * <p>
- * Because the output instance is held in a WeakReference, it is subject to aggressive
- * garbage collection if it is otherwise weakly reachable (i.e. no strong or soft references 
- * to it are held outside of this factory), ostensibly defeating the purpose of this factory.
- * Therefore if the lifecycle of external strong or soft references to any obtained output 
- * instances obtained from the factory is shorter than the desired lifecyle of the output instance 
- * (i.e. callers do not hold a strong or soft reference to an output instance for at least as 
- * long as to the input instance), then an option <code>requireExplicitRelease</code> is provided 
- * that causes the factory to internally maintain a strong reference to each output instance.
- * This inhibits the garbage collection of the output instance. If this option is enabled,
- * then callers must explicity indicate when the output instance may be garbage collected by 
- * calling {@link #release(Object)}.  Failure to release an output instance when necessary
- * will result in a memory leak of the output instance as well as the input instance (if
- * the output instance holds a strong or soft reference to the input instance).
- * </p>
- * 
- * <p>
- * The default value of <code>requireExplicitRelease</code> is <code>false</code>.  This is appropriate
- * for cases where calling code holds long-lived strong or soft references to the output instance,
- * typically as long or longer than references to the corresponding input instance, or where explict release 
- * is undesirable or impractical.
- * </p>
- * 
- * <p>
- * Subclasses of this class might also implement automatic release of output instances,
- * instead of or in addition to, the explicit release mechanism supported by this class.
- * This might be based for example on mechanisms such as object aging or a fixed size FIFO queue.
- * </p>
- *
- * @param <Input> the factory input class type
- * @param <Output> the factory output class type
- */
-public abstract class AbstractWrappedSingletonFactory<Input, Output> 
-        extends AbstractSingletonFactory<Input, Output> {
-    
-    /** Class logger. */
-    private final Logger log = LoggerFactory.getLogger(AbstractWrappedSingletonFactory.class);
-    
-    /** Storage for the factory. */
-    private WeakHashMap<Input, WeakReference<Output>> map;
-    
-    /** Set which holds a separate strong reference to output class instances,
-     * to inhibit garbage collection of the referent of the WeakReference. */
-    private HashSet<Output> outputSet;
-    
-    /** Flag indicating whether explicit release of the output instances is required. */
-    private boolean explicitRelease;
-    
-    /** Constructor. */
-    public AbstractWrappedSingletonFactory() {
-        this(false);
-    }
-    
-    /**
-     * Constructor.
-     *
-     * @param requireExplicitRelease if true, callers must explicitly release
-     *              output instances when garbage collection is desired.
-     */
-    public AbstractWrappedSingletonFactory(final boolean requireExplicitRelease) {
-        map = new WeakHashMap<>();
-        explicitRelease = requireExplicitRelease;
-        outputSet = new HashSet<>();
-    }
-    
-    /**
-     * Obtain an instance of the output class based on an input class instance.
-     * 
-     * @param input the input class instance
-     * @return an output class instance
-     */
-    public synchronized Output getInstance(final Input input) {
-        final Output output = super.getInstance(input);
-        
-        if (explicitRelease && output != null) {
-            log.trace("Explicit release was indicated, registering output instance to inhibit garbage collection");
-            register(output);
-        }
-        
-        return output;
-    }
-    
-    /**
-     * Get whether explict release of output instances is required,
-     * in order to allow garbage collection and prevent memory leaks.
-     * 
-     * @return true if enabled, false otherwise
-     */
-    public boolean isRequireExplicitRelease() {
-        return explicitRelease;
-    }
-    
-    /**
-     * Release the specified output instance so that, as the referent
-     * of a WeakReference, it may be garbage collected when it otherwise
-     * becomse weakly reachable.
-     * 
-     * @param output the output instance to release
-     */
-    public synchronized void release(final Output output) {
-        outputSet.remove(output);
-    }
-    
-    /**
-     * Release all currently held output instances so they
-     * may be garbage collected when they become otherwise
-     * weakly reachable.
-     */
-    public synchronized void releaseAll() {
-        outputSet.clear();
-    }
-    
-    /**
-     * Register the output instance so as to inhibit garbage collection.
-     * 
-     * @param output the ouput instance to register
-     */
-    protected synchronized void register(final Output output) {
-        outputSet.add(output);
-    }
-    
-    /**
-     * {@inheritDoc}
-     * 
-     * <p>
-     * The output instance will be automatically unwrapped from within the WeakReference.
-     * </p>
-     * 
-     * <p>
-     * Note this will return null if either the input does not
-     * currently have an associated output, or if the WeakReference
-     * to the output stored had already been clearly in preparation
-     * for garbage collection.
-     * </p>
-     */
-    protected synchronized Output get(final Input input) {
-        final WeakReference<Output> outputRef = map.get(input);
-        if (outputRef != null) {
-            log.trace("Input key mapped to a non-null WeakReference");
-            if (outputRef.get() != null) {
-                log.trace("WeakReference referent was non-null, returning referent");
-                return outputRef.get();
-            }
-            log.trace("WeakReference referent was null, removing WeakReference entry from map");
-            map.remove(input);
-        }
-        return null;
-    }
-    
-    /**
-     * {@inheritDoc}
-     * 
-     * <p>
-     * The output instance will be automatically wrapped in a WeakReference.
-     * </p>
-     */
-    protected synchronized void put(final Input input, final Output output) {
-        map.put(input, new WeakReference<>(output));
-    }
-
-}
\ No newline at end of file
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/SingletonFactory.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/SingletonFactory.java
deleted file mode 100644
index 3e4314f6a..000000000
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/util/SingletonFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID 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.opensaml.core.xml.util;
-
-/**
- * An interface for factory classes which implement a singleton pattern for producing an
- * output class based on an input class.
- * 
- * <p>
- * Classes which implement this interface should ensure that exactly one instance of a given output
- * class is returned from the factory for a given instance of an input class.
- * </p>
- *
- * @param <Input> the factory input class type
- * @param <Output> the factory output class type
- */
-public interface SingletonFactory<Input, Output> {
-
-    /**
-     * Obtain an instance of the output class based on an input class instance.
-     * 
-     * @param input the input class instance
-     * @return an output class instance
-     */
-    Output getInstance(Input input);
-
-}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list