ICEfaces
  1. ICEfaces
  2. ICE-5434

Suggestions for Output Resource Component API

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.0-Alpha2
    • Fix Version/s: 2.0-Alpha3
    • Component/s: None
    • Labels:
      None
    • Environment:
      all
    • Affects:
      Documentation (User Guide, Ref. Guide, etc.), Compatibility/Configuration

      Description

      Having used the OutputResource component for a services job, I found it to be unintuitive and at times clumsy. There are two main points:

      The Resource API defines an open() method but does not define a close() method. This means that ICEfaces is closing resources that it did not open (bad software engineering - can easily introduce side effects). This works in the trivial case but in the case of SFTP there are a number of other resources that must be closed as well. In order to use this API I had to Decorate the resources into an InputStream interface that overrode the close method to cleanup properly. This felt very clumsy and I think most developers would not come to this solution easily.

      Here is my proposal:

      Change the component contract to more reflect the streamingInputFile component contract. Let there be an attrubute "inputStream" that can value bind to a method that returns an input stream. The component should also allow a method binding to an actionListener. This action listener will get called on an error or on streaming finish. The actionListener should get called once and only once for every invocation of the input stream getter method. In this way, the stream can be safely opened in the getter (and any other associated resources can be maintained in the bean). The resources can then be properly cleaned up in the actionListener.

      Unless there is a good reason to use the Resource API I would suggest deprecating it in favor of this simpler API.

      Alternatively, if the Resource API is chosen as the path to use, an abstract close() method should be added that can be overridden to clean up an state associated with that resource.

        Activity

        Hide
        Ted Goddard added a comment -

        Likely also require bindings for resource name and etag.

        Show
        Ted Goddard added a comment - Likely also require bindings for resource name and etag.
        Hide
        Mark Collette added a comment -

        The problem is, the resources are served outside of a JSF lifecycle, so any component attributes are inaccessible. Maybe these callbacks could be added to the Resource interface, in some analog to ActionListener vs ActionListener2.

        Show
        Mark Collette added a comment - The problem is, the resources are served outside of a JSF lifecycle, so any component attributes are inaccessible. Maybe these callbacks could be added to the Resource interface, in some analog to ActionListener vs ActionListener2.
        Hide
        Mircea Toma added a comment -

        > The Resource API defines an open() method but does not define a close() method. This means that
        > ICEfaces is closing resources that it did not open (bad software engineering - can easily introduce
        > side effects).

        The close() method belongs to the InputStream because a Resource can be asked many times to create an InputStream. If the close() method would belong to the Resource than it's not clear anymore which of the streams created in the past are supposed to be closed.

        >This works in the trivial case but in the case of SFTP there are a number of other resources that must
        > be closed as well. In order to use this API I had to Decorate the resources into an InputStream
        > interface that overrode the close method to cleanup properly. This felt very clumsy and I think
        > most developers would not come to this solution easily.

        I believe decorating/wrapping the InputStream is the correct way. In the majority of cases the generated streams do not require additional operations executed when close() method is invoked. For those special cases java.io.FilterInputStream is a handy and simple class that can be used to intercept close() method invocation.

        Show
        Mircea Toma added a comment - > The Resource API defines an open() method but does not define a close() method. This means that > ICEfaces is closing resources that it did not open (bad software engineering - can easily introduce > side effects). The close() method belongs to the InputStream because a Resource can be asked many times to create an InputStream. If the close() method would belong to the Resource than it's not clear anymore which of the streams created in the past are supposed to be closed. >This works in the trivial case but in the case of SFTP there are a number of other resources that must > be closed as well. In order to use this API I had to Decorate the resources into an InputStream > interface that overrode the close method to cleanup properly. This felt very clumsy and I think > most developers would not come to this solution easily. I believe decorating/wrapping the InputStream is the correct way. In the majority of cases the generated streams do not require additional operations executed when close() method is invoked. For those special cases java.io.FilterInputStream is a handy and simple class that can be used to intercept close() method invocation.
        Hide
        Mircea Toma added a comment -

        See my comment above. Component related issues are better to be answered by somebody from the component team.

        Show
        Mircea Toma added a comment - See my comment above. Component related issues are better to be answered by somebody from the component team.
        Hide
        Ken Fyten added a comment -

        We believe that using the stream .close() method is the correct approach.

        Show
        Ken Fyten added a comment - We believe that using the stream .close() method is the correct approach.

          People

          • Assignee:
            Unassigned
            Reporter:
            Patrick Wilson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: