You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Andrei Pozolotin (JIRA)" <ji...@apache.org> on 2011/05/14 06:10:47 UTC
[jira] [Created] (FELIX-2951) guidelines: felix osgi bundle class
load vs
Thread.currentThread().getContextClassLoader().getResource("")
guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
------------------------------------------------------------------------------------------------------------------
Key: FELIX-2951
URL: https://issues.apache.org/jira/browse/FELIX-2951
Project: Felix
Issue Type: Improvement
Components: Framework
Affects Versions: framework-3.2.1
Reporter: Andrei Pozolotin
Richard, hello;
1) here you say
http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
that "There is no reliable way to do this since..."
2) this project
http://pivot.apache.org/index.html
is using this kind of pattern quite often:
ImageView ::
/**
* Sets the image view's image by {@linkplain ClassLoader#getResource(String)
* resource name}.
*
* @param imageName
* The resource name of the image to set.
*
* @see #setImage(URL)
*/
public final void setImage(String imageName) {
if (imageName == null) {
throw new IllegalArgumentException("imageName is null.");
}
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
setImage(classLoader.getResource(imageName.substring(1)));
}
3) instead of trying to work around this inside of felix, can you please provide
a set of guidelines for developers of projects such as apache pivot,
so the issue is gone?
thank you;
Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Andrei Pozolotin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13033570#comment-13033570 ]
Andrei Pozolotin commented on FELIX-2951:
-----------------------------------------
one set of solutions:
http://njbartlett.name/2010/08/30/osgi-readiness-loading-classes.html
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Andrei Pozolotin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13033515#comment-13033515 ]
Andrei Pozolotin commented on FELIX-2951:
-----------------------------------------
the dreaded workaround which we are trying to avoid in osgi bundle code:
http://stackoverflow.com/questions/2198928/better-handling-of-thread-context-classloader-in-osgi
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
/*
* Start threads, or establish connections, here, now
*/
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Richard S. Hall (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13049337#comment-13049337 ]
Richard S. Hall commented on FELIX-2951:
----------------------------------------
This is a issue without a single solution. You are basically left with
one of these choices:
* Bracket calls into libraries using TCCL to set/unset it to the
desired value.
* Modify libraries using TCCL to better guess which class loader to use.
o Maybe the client passes a client-side object which has the
correct class loader.
o Explicitly ask for a class loader in the library method.
* Use services.
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Andrei Pozolotin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13049319#comment-13049319 ]
Andrei Pozolotin commented on FELIX-2951:
-----------------------------------------
https://issues.apache.org/jira/browse/PIVOT-742
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Andrei Pozolotin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13049330#comment-13049330 ]
Andrei Pozolotin commented on FELIX-2951:
-----------------------------------------
"context finder" here:
http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements
actually sounds like a good idea; does felix has something similar to it?
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Andrei Pozolotin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13033567#comment-13033567 ]
Andrei Pozolotin commented on FELIX-2951:
-----------------------------------------
original thread in pivot
http://mail-archives.apache.org/mod_mbox/pivot-user/201105.mbox/%3C4DCDF889.10506@gmail.com%3E
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Andrei Pozolotin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13033566#comment-13033566 ]
Andrei Pozolotin commented on FELIX-2951:
-----------------------------------------
or may be felix has alternative to this:
http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Issue Comment Edited] (FELIX-2951) guidelines: felix osgi
bundle class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Andrei Pozolotin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13049338#comment-13049338 ]
Andrei Pozolotin edited comment on FELIX-2951 at 6/14/11 7:02 PM:
------------------------------------------------------------------
thanks for the link; your position makes sense.
to summarize what you said before, the options are:
#################################################
* Bracket calls into libraries using TCCL to set/unset it to the
desired value.
* Modify libraries using TCCL to better guess which class loader to use.
o Maybe the client passes a client-side object which has the
correct class loader.
o Explicitly ask for a class loader in the library method.
* Use services.
* Use own context finder.
#################################################
was (Author: andrei.pozolotin):
thanks for the lik; your position makes sense.
to summarize what you said before, the options are:
#################################################
* Bracket calls into libraries using TCCL to set/unset it to the
desired value.
* Modify libraries using TCCL to better guess which class loader to use.
o Maybe the client passes a client-side object which has the
correct class loader.
o Explicitly ask for a class loader in the library method.
* Use services.
* Use own context finder.
#################################################
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Richard S. Hall (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13049333#comment-13049333 ]
Richard S. Hall commented on FELIX-2951:
----------------------------------------
Regardin "context finder", no, the Felix framework doesn't have something similar because there are issues with that approach too, e.g.:
http://www.mail-archive.com/equinox-dev@eclipse.org/msg03304.html
And we try to avoid containerisms as much as possible in Felix.
Technically, isn't it possible to provide your own context finder? Isn't that value inherited by threads? If so, just start the Felix framework with a thread whose TCCL is set to your context finder, then the framework threads will have it too, no?
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle
class load vs
Thread.currentThread().getContextClassLoader().getResource("")
Posted by "Andrei Pozolotin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13049338#comment-13049338 ]
Andrei Pozolotin commented on FELIX-2951:
-----------------------------------------
thanks for the lik; your position makes sense.
to summarize what you said before, the options are:
#################################################
* Bracket calls into libraries using TCCL to set/unset it to the
desired value.
* Modify libraries using TCCL to better guess which class loader to use.
o Maybe the client passes a client-side object which has the
correct class loader.
o Explicitly ask for a class loader in the library method.
* Use services.
* Use own context finder.
#################################################
> guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("")
> ------------------------------------------------------------------------------------------------------------------
>
> Key: FELIX-2951
> URL: https://issues.apache.org/jira/browse/FELIX-2951
> Project: Felix
> Issue Type: Improvement
> Components: Framework
> Affects Versions: framework-3.2.1
> Reporter: Andrei Pozolotin
>
> Richard, hello;
> 1) here you say
> http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html
> that "There is no reliable way to do this since..."
> 2) this project
> http://pivot.apache.org/index.html
> is using this kind of pattern quite often:
> ImageView ::
> /**
> * Sets the image view's image by {@linkplain ClassLoader#getResource(String)
> * resource name}.
> *
> * @param imageName
> * The resource name of the image to set.
> *
> * @see #setImage(URL)
> */
> public final void setImage(String imageName) {
> if (imageName == null) {
> throw new IllegalArgumentException("imageName is null.");
> }
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> setImage(classLoader.getResource(imageName.substring(1)));
> }
> 3) instead of trying to work around this inside of felix, can you please provide
> a set of guidelines for developers of projects such as apache pivot,
> so the issue is gone?
> thank you;
> Andrei
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira