Ignore:
Timestamp:
06/24/13 13:38:40 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/communication/Subscription.java

    r84 r85  
    11package com.framsticks.communication;
    22
     3import java.util.List;
     4
    35import com.framsticks.communication.queries.RegistrationRequest;
    4 import com.framsticks.util.dispatching.AtOnceDispatcher;
    56import com.framsticks.util.dispatching.Dispatcher;
     7import com.framsticks.util.dispatching.Dispatching;
     8import com.framsticks.util.dispatching.RunAt;
    69import com.framsticks.util.StateFunctor;
    710import org.apache.log4j.Logger;
     
    1114 * @author Piotr Sniegowski
    1215 */
    13 public class Subscription {
     16public class Subscription<C> {
    1417
    15     private final static Logger log = Logger.getLogger(Subscription.class);
     18        private final static Logger log = Logger.getLogger(Subscription.class);
    1619
    17     private final ClientConnection connection;
    18     private final String path;
     20        private final ClientConnection connection;
     21        private final String path;
    1922        private final String registeredPath;
    20     private Dispatcher dispatcher = AtOnceDispatcher.instance;
     23        private final Dispatcher<C> dispatcher;
    2124
    2225        private EventCallback eventCallback;
    2326
    24         public Subscription(ClientConnection connection, String path, String registeredPath) {
     27        public Subscription(ClientConnection connection, String path, String registeredPath, Dispatcher<C> dispatcher) {
    2528                this.connection = connection;
    26         this.path = path;
     29                this.path = path;
    2730                this.registeredPath = registeredPath;
     31                this.dispatcher = dispatcher;
    2832        }
    2933
     
    4145        }
    4246
    43     public void setDispatcher(Dispatcher dispatcher) {
    44         this.dispatcher = dispatcher;
    45     }
     47        public void unsubscribe(final StateFunctor stateFunctor) {
     48                //@todo remove that /cli/ prefix, when registeredPath will be a fully qualified path
     49                connection.send(new RegistrationRequest().register(false).path(registeredPath), new ResponseCallback<Connection>() {
     50                        @Override
     51                        public void process(Response response) {
     52                                if (!response.getOk()) {
     53                                        log.error("failed to unsunscribe " + this + ": " + response.getComment());
     54                                        stateFunctor.call(new Exception(response.getComment()));
     55                                        return;
     56                                }
     57                                assert response.hasFiles();
     58                                log.debug("unsunscribed " + this);
     59                                stateFunctor.call(null);
     60                        }
     61                });
     62        }
    4663
    47     public void unsubscribe(final StateFunctor stateFunctor) {
    48         //@todo remove that /cli/ prefix, when registeredPath will be a fully qualified path
    49         connection.send(new RegistrationRequest().register(false).setPath(registeredPath), new ResponseCallback() {
    50             @Override
    51             public void process(Response response) {
    52                 if (!response.getOk()) {
    53                     log.error("failed to unsunscribe " + this + ": " + response.getComment());
    54                     stateFunctor.call(new Exception(response.getComment()));
    55                     return;
    56                 }
    57                 assert response.hasFiles();
    58                 log.debug("unsunscribed " + this);
    59                 stateFunctor.call(null);
    60             }
    61         });
    62     }
     64        public EventCallback getEventCallback() {
     65                return eventCallback;
     66        }
    6367
    64     public EventCallback getEventCallback() {
    65         return eventCallback;
    66     }
     68        public Dispatcher<C> getDispatcher() {
     69                return dispatcher;
     70        }
    6771
    68     public Dispatcher getDispatcher() {
    69         return dispatcher;
    70     }
     72        public void setEventCallback(EventCallback eventCallback) {
     73                this.eventCallback = eventCallback;
     74        }
    7175
    72     public void setEventCallback(EventCallback eventCallback) {
    73         this.eventCallback = eventCallback;
    74     }
     76        public void dispatchCall(final List<File> files) {
     77                Dispatching.invokeLaterOrNow(dispatcher, new RunAt<C>() {
     78                        @Override
     79                        public void run() {
     80                                eventCallback.call(files);
     81                        }
     82                });
     83        }
    7584}
Note: See TracChangeset for help on using the changeset viewer.