[ 
https://issues.apache.org/jira/browse/PIVOT-743?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13034524#comment-13034524
 ] 

Andrei Pozolotin commented on PIVOT-743:
----------------------------------------

APPLETS:

1) this project:
https://github.com/carrot-garden/carrot-bugger/tree/master/carrot-bug-pivot-static-core
with this launcher:
https://github.com/carrot-garden/carrot-bugger/tree/master/carrot-bug-pivot-static-launch

2) uses 3 files
https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/MainPivot.java
https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/MainPivot.bxml
https://github.com/carrot-garden/carrot-bugger/blob/master/carrot-bug-pivot-static-core/src/main/java/com/carrotgarden/test/WindowExtra.java

3) with 1 static counter:

public class WindowExtra extends Window implements Bindable {

protected static final Logger log = LoggerFactory
.getLogger(WindowExtra.class);

private static final AtomicInteger COUNTER = new AtomicInteger(0);

@Override
public void initialize(Map<String, Object> namespace, URL location,
Resources resources) {

Label counterLabel = (Label) namespace.get("counter");

counterLabel.setText("" + COUNTER.getAndIncrement());

}

}

4) you can try for yourself here:
http://www.carrotgarden.com:8080/webstart-carrot-bug-pivot-applet-static-staging/

when you select launch mode "applet (plugin V1)" (AKA "legacy", "non-jnlp", 
"apple-default")
you will get an applet with counter that gets incremented on every applet 
reload;

since I it is hard to tell how all the static fields in pivot interact, my 
concerns with pivot are:
* memory leaks;
* cross-page applet interferences;
* security;

thanks.


> pivot & static
> --------------
>
>                 Key: PIVOT-743
>                 URL: https://issues.apache.org/jira/browse/PIVOT-743
>             Project: Pivot
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Andrei Pozolotin
>             Fix For: 2.1
>
>
> Greg, hello:
> 1) in this example you say:
> http://pivot.apache.org/tutorials/list-buttons.html
> "Note that this example makes use of the global resource cache to store the 
> loaded images."
> 2) which reminds of the "java evil singleton pattern"
> http://java.sun.com/developer/technicalArticles/Programming/singletons/
> http://www.ibm.com/developerworks/webservices/library/co-single/index.html
> http://beust.com/weblog/2011/03/10/rehabilitating-the-singleton-pattern/
> http://tech.puredanger.com/2007/07/03/pattern-hate-singleton/
> and the consensus seems to be: 
> "Singletons are fine as long as you don't implement them with static" 
> 3) and pivot uses them freely; few examples
> public abstract class ApplicationContext {
>     protected static ArrayList<Display> displays = new ArrayList<Display>();
>     protected static ArrayList<Application> applications = new 
> ArrayList<Application>();
>     private static HashMap<URI, Object> resourceCache = new HashMap<URI, 
> Object>();
>     private static ResourceCacheDictionary resourceCacheDictionary = new 
> ResourceCacheDictionary();
> public abstract class Theme {
>     private static Theme theme = null;
> 4) do you think is it feasible to convert all of pivot into SPI:
>               ServiceLoader<PivotFrameworkFactory> loader = 
> ServiceLoader.load(PivotFrameworkFactory.class);
>               PivotFrameworkFactory factory = loader.iterator().next();
>               Map<String, Object> config = new HashMap<String, Object>();
>               PivotFramework framework = factory.newFramework(config);
> 5) the two use cases that affect me now:
> a) applet reload shares static
> b) pivot + osgi (not sure yet if I can find a workaround; possibly depends on 
> what you do about PIVOT-742 PIVOT-22)
> thank you;
> Andrei

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to