You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Joerg Schaible (JIRA)" <ji...@apache.org> on 2009/12/23 20:36:29 UTC

[jira] Created: (LANG-577) Add ObjectReference interface and two implementations

Add ObjectReference interface and two implementations
-----------------------------------------------------

                 Key: LANG-577
                 URL: https://issues.apache.org/jira/browse/LANG-577
             Project: Commons Lang
          Issue Type: New Feature
          Components: lang.*
            Reporter: Joerg Schaible
            Assignee: Joerg Schaible
            Priority: Minor
             Fix For: 3.0


In some situations it would be helpful to use a reference to an object, e.g. for parameters by reference

{code:java}
void doSomething(ObjectReference<String> ref) {
    ref.set("Hello");
}
{code}

or for anonymous methods

{code:java}
final ObjectReference<String> ref = new MemoryReference<String>();
final Runnable r = new Runnable() {
    void run() {
        ref.set("Hello");
    }
}
r.run();
{code}

Additionally it is sometimes useful to keep the reference in other places than in shared memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even in combination with some other persistence mechanism. Basically I am proposing the interface ObjectReference:

{code:Java}
/**
 * Interface to reference an object.
 * 
 * @param <T> the type of the referenced object
 * @author Apache Software Foundation
 * @since 3.0
 */
public interface ObjectReference<T> {
    /**
     * Getter for the referenced object.
     * 
     * @return the object or <code>null</code>
     */
    T get();

    /**
     * Setter for the reference.
     * 
     * @param object the object to reference (may be <code>null</code>)
     */
    void set(T object);
}
{code}

and the two implementations MemoryReference and ThreadLocalReference in the new package org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.

Comments?

Unit test will be provided also.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-577) Add ObjectReference interface and two implementations

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-577?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joerg Schaible updated LANG-577:
--------------------------------

    Attachment: reference.diff

> Add ObjectReference interface and two implementations
> -----------------------------------------------------
>
>                 Key: LANG-577
>                 URL: https://issues.apache.org/jira/browse/LANG-577
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Joerg Schaible
>            Assignee: Joerg Schaible
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: reference.diff
>
>
> In some situations it would be helpful to use a reference to an object, e.g. for parameters by reference
> {code:java}
> void doSomething(ObjectReference<String> ref) {
>     ref.set("Hello");
> }
> {code}
> or for anonymous methods
> {code:java}
> final ObjectReference<String> ref = new MemoryReference<String>();
> final Runnable r = new Runnable() {
>     void run() {
>         ref.set("Hello");
>     }
> }
> r.run();
> {code}
> Additionally it is sometimes useful to keep the reference in other places than in shared memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even in combination with some other persistence mechanism. Basically I am proposing the interface ObjectReference:
> {code:Java}
> /**
>  * Interface to reference an object.
>  * 
>  * @param <T> the type of the referenced object
>  * @author Apache Software Foundation
>  * @since 3.0
>  */
> public interface ObjectReference<T> {
>     /**
>      * Getter for the referenced object.
>      * 
>      * @return the object or <code>null</code>
>      */
>     T get();
>     /**
>      * Setter for the reference.
>      * 
>      * @param object the object to reference (may be <code>null</code>)
>      */
>     void set(T object);
> }
> {code}
> and the two implementations MemoryReference and ThreadLocalReference in the new package org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.
> Comments?
> Unit test will be provided also.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-577) Add ObjectReference interface and two implementations

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12794453#action_12794453 ] 

Matt Benson commented on LANG-577:
----------------------------------

I'll buy this, because Java includes neither a StrongReference class nor the means to implement one.  Thanks!

> Add ObjectReference interface and two implementations
> -----------------------------------------------------
>
>                 Key: LANG-577
>                 URL: https://issues.apache.org/jira/browse/LANG-577
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Joerg Schaible
>            Assignee: Joerg Schaible
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: reference.diff
>
>
> In some situations it would be helpful to use a reference to an object, e.g. for parameters by reference
> {code:java}
> void doSomething(ObjectReference<String> ref) {
>     ref.set("Hello");
> }
> {code}
> or for anonymous methods
> {code:java}
> final ObjectReference<String> ref = new MemoryReference<String>();
> final Runnable r = new Runnable() {
>     void run() {
>         ref.set("Hello");
>     }
> }
> r.run();
> {code}
> Additionally it is sometimes useful to keep the reference in other places than in shared memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even in combination with some other persistence mechanism. Basically I am proposing the interface ObjectReference:
> {code:Java}
> /**
>  * Interface to reference an object.
>  * 
>  * @param <T> the type of the referenced object
>  * @author Apache Software Foundation
>  * @since 3.0
>  */
> public interface ObjectReference<T> {
>     /**
>      * Getter for the referenced object.
>      * 
>      * @return the object or <code>null</code>
>      */
>     T get();
>     /**
>      * Setter for the reference.
>      * 
>      * @param object the object to reference (may be <code>null</code>)
>      */
>     void set(T object);
> }
> {code}
> and the two implementations MemoryReference and ThreadLocalReference in the new package org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.
> Comments?
> Unit test will be provided also.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-577) Add ObjectReference interface and two implementations

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-577?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-577:
-------------------------------

    Fix Version/s:     (was: 3.0)
                   3.1

No backwards compat issues, so moving to 3.1. If resolved before 3.0 is released please assign to 3.0.

> Add ObjectReference interface and two implementations
> -----------------------------------------------------
>
>                 Key: LANG-577
>                 URL: https://issues.apache.org/jira/browse/LANG-577
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Joerg Schaible
>            Assignee: Joerg Schaible
>            Priority: Minor
>             Fix For: 3.1
>
>         Attachments: reference.diff
>
>
> In some situations it would be helpful to use a reference to an object, e.g. for parameters by reference
> {code:java}
> void doSomething(ObjectReference<String> ref) {
>     ref.set("Hello");
> }
> {code}
> or for anonymous methods
> {code:java}
> final ObjectReference<String> ref = new MemoryReference<String>();
> final Runnable r = new Runnable() {
>     void run() {
>         ref.set("Hello");
>     }
> }
> r.run();
> {code}
> Additionally it is sometimes useful to keep the reference in other places than in shared memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even in combination with some other persistence mechanism. Basically I am proposing the interface ObjectReference:
> {code:Java}
> /**
>  * Interface to reference an object.
>  * 
>  * @param <T> the type of the referenced object
>  * @author Apache Software Foundation
>  * @since 3.0
>  */
> public interface ObjectReference<T> {
>     /**
>      * Getter for the referenced object.
>      * 
>      * @return the object or <code>null</code>
>      */
>     T get();
>     /**
>      * Setter for the reference.
>      * 
>      * @param object the object to reference (may be <code>null</code>)
>      */
>     void set(T object);
> }
> {code}
> and the two implementations MemoryReference and ThreadLocalReference in the new package org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.
> Comments?
> Unit test will be provided also.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-577) Add ObjectReference interface and two implementations

Posted by "Matt Benson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12794449#action_12794449 ] 

Matt Benson commented on LANG-577:
----------------------------------

How does this augment/improve upon the Reference classes available with Java >= 2?

> Add ObjectReference interface and two implementations
> -----------------------------------------------------
>
>                 Key: LANG-577
>                 URL: https://issues.apache.org/jira/browse/LANG-577
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Joerg Schaible
>            Assignee: Joerg Schaible
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: reference.diff
>
>
> In some situations it would be helpful to use a reference to an object, e.g. for parameters by reference
> {code:java}
> void doSomething(ObjectReference<String> ref) {
>     ref.set("Hello");
> }
> {code}
> or for anonymous methods
> {code:java}
> final ObjectReference<String> ref = new MemoryReference<String>();
> final Runnable r = new Runnable() {
>     void run() {
>         ref.set("Hello");
>     }
> }
> r.run();
> {code}
> Additionally it is sometimes useful to keep the reference in other places than in shared memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even in combination with some other persistence mechanism. Basically I am proposing the interface ObjectReference:
> {code:Java}
> /**
>  * Interface to reference an object.
>  * 
>  * @param <T> the type of the referenced object
>  * @author Apache Software Foundation
>  * @since 3.0
>  */
> public interface ObjectReference<T> {
>     /**
>      * Getter for the referenced object.
>      * 
>      * @return the object or <code>null</code>
>      */
>     T get();
>     /**
>      * Setter for the reference.
>      * 
>      * @param object the object to reference (may be <code>null</code>)
>      */
>     void set(T object);
> }
> {code}
> and the two implementations MemoryReference and ThreadLocalReference in the new package org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.
> Comments?
> Unit test will be provided also.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-577) Add ObjectReference interface and two implementations

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12804410#action_12804410 ] 

Henri Yandell commented on LANG-577:
------------------------------------

The API does appear to be a match for MutableObject.

> Add ObjectReference interface and two implementations
> -----------------------------------------------------
>
>                 Key: LANG-577
>                 URL: https://issues.apache.org/jira/browse/LANG-577
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Joerg Schaible
>            Assignee: Joerg Schaible
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: reference.diff
>
>
> In some situations it would be helpful to use a reference to an object, e.g. for parameters by reference
> {code:java}
> void doSomething(ObjectReference<String> ref) {
>     ref.set("Hello");
> }
> {code}
> or for anonymous methods
> {code:java}
> final ObjectReference<String> ref = new MemoryReference<String>();
> final Runnable r = new Runnable() {
>     void run() {
>         ref.set("Hello");
>     }
> }
> r.run();
> {code}
> Additionally it is sometimes useful to keep the reference in other places than in shared memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even in combination with some other persistence mechanism. Basically I am proposing the interface ObjectReference:
> {code:Java}
> /**
>  * Interface to reference an object.
>  * 
>  * @param <T> the type of the referenced object
>  * @author Apache Software Foundation
>  * @since 3.0
>  */
> public interface ObjectReference<T> {
>     /**
>      * Getter for the referenced object.
>      * 
>      * @return the object or <code>null</code>
>      */
>     T get();
>     /**
>      * Setter for the reference.
>      * 
>      * @param object the object to reference (may be <code>null</code>)
>      */
>     void set(T object);
> }
> {code}
> and the two implementations MemoryReference and ThreadLocalReference in the new package org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.
> Comments?
> Unit test will be provided also.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-577) Add ObjectReference interface and two implementations

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12794485#action_12794485 ] 

Oliver Heger commented on LANG-577:
-----------------------------------

Isn't this very similar to the {{MutableObject}} class already available in lang?

> Add ObjectReference interface and two implementations
> -----------------------------------------------------
>
>                 Key: LANG-577
>                 URL: https://issues.apache.org/jira/browse/LANG-577
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Joerg Schaible
>            Assignee: Joerg Schaible
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: reference.diff
>
>
> In some situations it would be helpful to use a reference to an object, e.g. for parameters by reference
> {code:java}
> void doSomething(ObjectReference<String> ref) {
>     ref.set("Hello");
> }
> {code}
> or for anonymous methods
> {code:java}
> final ObjectReference<String> ref = new MemoryReference<String>();
> final Runnable r = new Runnable() {
>     void run() {
>         ref.set("Hello");
>     }
> }
> r.run();
> {code}
> Additionally it is sometimes useful to keep the reference in other places than in shared memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even in combination with some other persistence mechanism. Basically I am proposing the interface ObjectReference:
> {code:Java}
> /**
>  * Interface to reference an object.
>  * 
>  * @param <T> the type of the referenced object
>  * @author Apache Software Foundation
>  * @since 3.0
>  */
> public interface ObjectReference<T> {
>     /**
>      * Getter for the referenced object.
>      * 
>      * @return the object or <code>null</code>
>      */
>     T get();
>     /**
>      * Setter for the reference.
>      * 
>      * @param object the object to reference (may be <code>null</code>)
>      */
>     void set(T object);
> }
> {code}
> and the two implementations MemoryReference and ThreadLocalReference in the new package org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.
> Comments?
> Unit test will be provided also.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-577) Add ObjectReference interface and two implementations

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12794452#action_12794452 ] 

Joerg Schaible commented on LANG-577:
-------------------------------------

They are not really related. The stuff in java.lang.ref is used more or less to interact with the garbage collector and has very specialized functionality to deal with the lifecycle of objects that are no longer referenced by an application. The proposal here describes a way to share an object within some kind of scope scope using an explicit reference with very simple functionality.

> Add ObjectReference interface and two implementations
> -----------------------------------------------------
>
>                 Key: LANG-577
>                 URL: https://issues.apache.org/jira/browse/LANG-577
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Joerg Schaible
>            Assignee: Joerg Schaible
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: reference.diff
>
>
> In some situations it would be helpful to use a reference to an object, e.g. for parameters by reference
> {code:java}
> void doSomething(ObjectReference<String> ref) {
>     ref.set("Hello");
> }
> {code}
> or for anonymous methods
> {code:java}
> final ObjectReference<String> ref = new MemoryReference<String>();
> final Runnable r = new Runnable() {
>     void run() {
>         ref.set("Hello");
>     }
> }
> r.run();
> {code}
> Additionally it is sometimes useful to keep the reference in other places than in shared memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even in combination with some other persistence mechanism. Basically I am proposing the interface ObjectReference:
> {code:Java}
> /**
>  * Interface to reference an object.
>  * 
>  * @param <T> the type of the referenced object
>  * @author Apache Software Foundation
>  * @since 3.0
>  */
> public interface ObjectReference<T> {
>     /**
>      * Getter for the referenced object.
>      * 
>      * @return the object or <code>null</code>
>      */
>     T get();
>     /**
>      * Setter for the reference.
>      * 
>      * @param object the object to reference (may be <code>null</code>)
>      */
>     void set(T object);
> }
> {code}
> and the two implementations MemoryReference and ThreadLocalReference in the new package org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.
> Comments?
> Unit test will be provided also.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.