This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 248126 - Intent API
Summary: Intent API
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Output Window (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal (vote)
Assignee: Jaroslav Havlin
URL:
Keywords: API_REVIEW
Depends on:
Blocks:
 
Reported: 2014-10-23 08:57 UTC by Jaroslav Havlin
Modified: 2014-12-11 12:59 UTC (History)
6 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Proposed Patch (56.18 KB, patch)
2014-10-23 08:57 UTC, Jaroslav Havlin
Details | Diff
Proposed Patch v2 (56.16 KB, patch)
2014-10-23 09:58 UTC, Jaroslav Havlin
Details | Diff
Proposed Patch v3 (62.80 KB, patch)
2014-10-23 19:28 UTC, Jaroslav Havlin
Details | Diff
Proposed Patch v4 (74.08 KB, patch)
2014-11-04 13:51 UTC, Jaroslav Havlin
Details | Diff
Generated JavaDoc (ZIP file) (89.70 KB, application/3dr)
2014-11-04 13:54 UTC, Jaroslav Havlin
Details
Proposed Patch v5 (85.51 KB, patch)
2014-11-11 13:26 UTC, Jaroslav Havlin
Details | Diff
Generated JavaDoc (ZIP file) (91.17 KB, patch)
2014-11-11 13:27 UTC, Jaroslav Havlin
Details | Diff
Proposed Patch v6 (121.71 KB, patch)
2014-11-26 16:31 UTC, Jaroslav Havlin
Details | Diff
Generated JavaDoc (ZIP file) (116.34 KB, application/3dr)
2014-11-26 16:33 UTC, Jaroslav Havlin
Details
Proposed Patch v7 (122.51 KB, patch)
2014-12-02 13:57 UTC, Jaroslav Havlin
Details | Diff
Generated JavaDoc (ZIP file) (116.48 KB, application/3dr)
2014-12-02 14:00 UTC, Jaroslav Havlin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Havlin 2014-10-23 08:57:38 UTC
Created attachment 150071 [details]
Proposed Patch

Review for new I/O API (bug 247404) showed that a new module for
handling of clicked URI hyperlinks is needed.

This module provides a contract between API clients that can express
some intention to invoke an operation (specified e.g. by a URI) and
SPI providers that can handle the URI.

This is useful in client-server environments, where the intention
can be constructed on server-side, but handled on client-side. The
objects that describe the intention should be easy to construct,
transfer and interpret.
Comment 1 Jaroslav Havlin 2014-10-23 08:59:59 UTC
Please review.
Comment 2 Martin Entlicher 2014-10-23 09:35:53 UTC
Looks good to me.
I'd only rename OpenUriHandler.handle(URI) to OpenUriHandler.open(URI).
Comment 3 Jaroslav Havlin 2014-10-23 09:58:18 UTC
Created attachment 150075 [details]
Proposed Patch v2

> I'd only rename OpenUriHandler.handle(URI) to OpenUriHandler.open(URI).
Renamed. Thank you, Martin.
Comment 4 Ralph Ruijs 2014-10-23 10:07:14 UTC
In the current design the api is not really about communicating some intent, but facilitates opening uris. Creating new interfaces and their implementations for every intent we want to communicate, as proposed by the documentation, will result in a very big module from which clients only use the "intent" they introduced.

R01: Can we make the api more generic? Or is there an intent object from a third-party library we can use?
Comment 5 Tomas Zezula 2014-10-23 11:00:49 UTC
If we want to stay only with URI intents and no additional data sent to from intent it's OK tom me. The URI intent is probably enough for output. We want to use the Intent for things like missing main class, app server and other UI stuff currently done in ActionProvider. It's OK for this as well.

However if you want to make the generic Intent API. The Intent is rather an Event (possibly parametrised) sent to global channel by source which is processed by a registered sink.
You can look at Android Intent API allowing protocol, contentType, class or action events which can transfer parameters and possibly return values. Here is a good Android Intent API introduction: http://www.vogella.com/tutorials/AndroidIntent/article.html
Comment 6 Jaroslav Havlin 2014-10-23 11:27:19 UTC
(In reply to Ralph Ruijs from comment #4)
> In the current design the api is not really about communicating some intent,
> but facilitates opening uris.
Yes, this is currently the only goal of this module.

I considered three possibilities:
 1) Use a more descriptive name for the module (e.g. api.openuri, api.uri.actions)
 2) Make its name more generic, so that similar APIs/SPIs for requesting and 
    handling of some operations can be added in the future (something with 
    similar purpose as Intent class in Android).
 3) Find an existing module where to put the classes.

I weren't able to find any suitable module, and #2 seemed slightly better than #1 to me. But #1 seems also quit fine to me if you prefer it.
Comment 7 Ralph Ruijs 2014-10-23 12:02:57 UTC
(In reply to Tomas Zezula from comment #5)
> If we want to stay only with URI intents and no additional data sent to from
> intent it's OK tom me. The URI intent is probably enough for output. We want
> to use the Intent for things like missing main class, app server and other
> UI stuff currently done in ActionProvider. It's OK for this as well.

It is probably OK for the ActionProvider stuff, but the usage wouldn't be very expressive, right?

> However if you want to make the generic Intent API. The Intent is rather an
> Event (possibly parametrised) sent to global channel by source which is
> processed by a registered sink.
> You can look at Android Intent API allowing protocol, contentType, class or
> action events which can transfer parameters and possibly return values. Here
> is a good Android Intent API introduction:
> http://www.vogella.com/tutorials/AndroidIntent/article.html

Jarda; the Android Intent API was the only one I could find quickly as well (although I expected to find a more generic library). Is there a reason not to shape the api towards the Android Intent classes?
Comment 8 Jaroslav Havlin 2014-10-23 12:33:05 UTC
> Jarda; the Android Intent API was the only one I could find quickly as well
> (although I expected to find a more generic library). Is there a reason not
> to shape the api towards the Android Intent classes?
No particular reason. I just did not have any use case for which URI opening is not sufficient. (The most common use case is opening file in editor using URI like "file:///path/to/file?line=123"). So I just chose generic module name so that we can add more sophisticated API later. But we can make it more generic directly.
Comment 9 Tomas Zezula 2014-10-23 12:45:08 UTC
In reply to Ralph:
>...usage wouldn't be very expressive, right?
Yes, the usage will be quite simple.
The thing is that the NB ActionProvider is an UI class which shows dialogs and expects response from the user, for example select active app server. On server side the ActionProvider or the replacement of ActionProvider will just emit an special URI to the console which shows in a browser a link, for example: Missing_Application_Server. When clicked the code on client or server side will handle it by action, for example let user select available app server.


In Reply to Jarda:
I vote for #2 but I would do these changes for easier extensibility in the future.
1st) Add a Intent class.

final class Intent<R> {
     static Intent forURI(URI){}
}

In future the Intent can have more factories like: forMimeType,forAction,forClass
and methods like addParameter.


2nd) Rename UriIntents to IntentManager.
class IntentManager {
    void execute(Intent<Void>);
    Future<? extends T> submit(Intent<T>);
}
Comment 10 Jaroslav Havlin 2014-10-23 19:28:42 UTC
Created attachment 150093 [details]
Proposed Patch v3

> In Reply to Jarda:
> I vote for #2 but I would do these changes for easier extensibility in the 
> future.
Thank you very much, Tomas, for your suggestions.
I made some slight modifications (commented below). If I understood some of your ideas incorrectly, please let me know.

> 1st) Add a Intent class.
> 
> final class Intent<R> {
>     static Intent forURI(URI){}
> }
The class is not final, but it has a package-private constructor, so that implementations can be defined in package-private classes.

Type parameter of the Intent returned by forURI is Boolean (true if the URI was handled, false otherwise).

> 2nd) Rename UriIntents to IntentManager.
> class IntentManager {
>     void execute(Intent<Void>);
>     Future<? extends T> submit(Intent<T>);
> }
The execute() method can take Intent with any type parameter. If its return type is not Void, the return value will be simply ignored.

Cannot return type of submit() be "Future<T>" instead of 
"Future<? extends T>"?


The SPI is OK?
I think making it generic would be quite difficult, as we cannot look instances up by class and type parameters (because of type erasure).

Thank you for reviewing.
Comment 11 Tomas Zezula 2014-10-27 15:51:01 UTC
>The class is not final:
OK for me.

>The execute() method can take Intent with any type parameter
Yes, it can be wildcard <?>

>"Future<T>" instead of  "Future<? extends T>"
Yes, you can.


>The SPI is OK?
It can stay as it is in case of another Intent type a new SPI will be created.
Or it can be changed into generic SPI which intact will be the Intent.invoke, the IntentManager will lookup all IntentHandlers and ask them if they support given Intent
the first one which does will handle it.
But I have no opinion about this. Feel free to choose any implementation.
Comment 12 Jaroslav Tulach 2014-11-03 10:52:55 UTC
Y01 Please attach or point to generated Javadoc. It is usually better, for completely new modules to read the Javadoc than a diff.

Y02 I don't understand much the purpose of IntentManager in the API. The methods could be moved into Intent class. They would be easier to find for the API clients.

Y03 Please prevent instantiation of all URI handlers, when only some of them are needed. E.g. I'd suggest to create @OpenUriHandler.Registration where one could specify a URI scheme (with regular expression?) that is required to be matched before the handler even gets instantiated.

Y04 Sometimes there may be multiple handlers registered for the same URI. It would be nice if the the API could somehow display them (icon+displayname) and let the user choose from them.
Comment 13 Jaroslav Havlin 2014-11-04 13:51:30 UTC
Created attachment 150264 [details]
Proposed Patch v4

Patch updated for current jet-main sources.
It is now independent on patch for api.io.

> Y02 The methods could be moved into Intent class.
Methods from IntentManager moved to Intent class.

> Y03 Please prevent instantiation of all URI handlers.
@OpenUriHandler.Registration added. It specifies URI pattern as regular expression.
Comment 14 Jaroslav Havlin 2014-11-04 13:54:12 UTC
Created attachment 150265 [details]
Generated JavaDoc (ZIP file)

> Y01 Please attach or point to generated Javadoc.
Attached.

Thank you for your comments.
Comment 15 Jaroslav Havlin 2014-11-05 16:34:35 UTC
Summary of review meeting:

 - Use intent as final class holding pair (String, URI)
 - Remove Intent.execute()
 - Make Intent.submit() not static and rename it to execute()
 - Remove Handler to IntentAction
 - Make Intent.getAvailableHandlers() not static and rename it to getIntentActions()
 - Registration should apply to a static method, not interface
 - SPI method should take a parameter similar to FutureTask instead of
   returning Object.
 - IntentAction.execute() should return Future<Object>
Comment 16 Jaroslav Havlin 2014-11-11 13:26:26 UTC
Created attachment 150429 [details]
Proposed Patch v5

> - Use intent as final class holding pair (String, URI)
> - Remove Intent.execute()
> - Make Intent.submit() not static and rename it to execute()
> - Remove Handler to IntentAction
> - Make Intent.getAvailableHandlers() not static and rename it to 
>   getIntentActions()
> - Registration should apply to a static method, not interface
> - IntentAction.execute() should return Future<Object>
Done.

> - SPI method should take a parameter similar to FutureTask instead of
>   returning Object.
FutureTask doesn't seem suitable for this, its set() method is protected.
I'm considering adding "ResultHandle" class with methods "setResult(Object)" and setException(Throwable).

We can also consider introducing variant of Intent.execute() that takes a callback as argument.
Comment 17 Jaroslav Havlin 2014-11-11 13:27:27 UTC
Created attachment 150431 [details]
Generated JavaDoc (ZIP file)
Comment 18 Jaroslav Tulach 2014-11-18 11:23:45 UTC
Cannot download and unzip the Javadoc.
Comment 19 Jaroslav Tulach 2014-11-18 11:31:54 UTC
Please ignore my previous comment. I managed to do it. Looking at it:

Y11 no package.html description for API and SPI
Y12 no Javadoc for Intent class
Y13 return type of getIntentActions should be declared immutable (if it is?)
Y13a possibly the return type of getIntentActions could be SortedSet<? extends IntentAction>
Y14 usecase is out of date. still talks about static method.
Y15 javadoc of IntentHandlerRegistration should contains a sample code (e.g. not only usecase should have it). Again usecase is out of date.
Y16 IntentHandlerRegistration does not talk about threading
Comment 20 Jaroslav Havlin 2014-11-26 16:31:44 UTC
Created attachment 150730 [details]
Proposed Patch v6

Added support for callbacks and handlers that take Result parameter.
Please see attached JavaDoc.

> Y11 no package.html description for API and SPI
Added package-info.java files.
> Y12 no Javadoc for Intent class
Added.
> Y13 return type of getIntentActions should be declared immutable (if it is?)
Fixed.
> Y13a possibly the return type of getIntentActions could be
> SortedSet<? extends IntentAction>
Fixed.
> Y14 usecase is out of date. still talks about static method.
Updated.
> Y15 javadoc of IntentHandlerRegistration should contains a sample code
> (e.g. not only usecase should have it). Again usecase is out of date.
I've added sample code to package info. It is referenced from class JavaDoc.
> Y16 IntentHandlerRegistration does not talk about threading
Added to package info.

Thank you for the comments.
Comment 21 Jaroslav Havlin 2014-11-26 16:33:56 UTC
Created attachment 150731 [details]
Generated JavaDoc (ZIP file)

Updated JavaDoc for patch v6.
Comment 22 Jaroslav Tulach 2014-12-01 14:55:49 UTC
I would link  API types in code samples with <a href="@TOP@/...Intent.html">Intent</a> their definition using the <a> tag. But otherwise OK. I don't have any other comments.
Comment 23 Jaroslav Havlin 2014-12-02 13:57:12 UTC
Created attachment 150841 [details]
Proposed Patch v7

I would link  API types in code samples [...] with their definition [...]
Fixed.

Thank you.
Comment 24 Jaroslav Havlin 2014-12-02 14:00:27 UTC
Created attachment 150842 [details]
Generated JavaDoc (ZIP file)

Updated JavaDoc for patch v7.
Comment 25 Jaroslav Havlin 2014-12-02 15:19:40 UTC
I would like to integrate the patch next Tuesday (Dec 9), providing there are no objections.
Comment 26 Tomas Zezula 2014-12-03 14:34:50 UTC
Seems good to me, feel free to integrate.
Comment 27 Jaroslav Havlin 2014-12-08 17:40:01 UTC
I'll integrate the patch tomorrow afternoon (unless any objection is raised).
Thank you very much for reviewing.
Comment 28 Jaroslav Havlin 2014-12-09 17:25:42 UTC
Integrated as http://hg.netbeans.org/core-main/rev/4b8bfb738638.
Comment 29 Quality Engineering 2014-12-11 12:59:43 UTC
Integrated into 'main-silver', will be available in build *201412111033* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/4b8bfb738638
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #248126: Intent API