Ignore:
Timestamp:
07/10/13 22:41:02 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGTS:

  • complete events implementation
  • add CLI in Java Framsticks server
  • add automatic registration for events in GUI
  • improve objects fetching (object are never overwritten with new instances)
  • properly react for ListChange? events
  • add ListPanel? with table view
    • columns to be shown may be statically specified in configuration
    • currently modyfying data through tables is not available
  • improve maven configuration
    • configuration file may be specified without touching pom.xml

CHANGELOG:
Extract constants from Flags into ParamFlags? and SetStateFlags?.

Extract flags I/O to FlagsUtils? class.

Configured maven to exec given resource configuration.

For example:
mvn exec:exec -Dframsticks.config=/configs/managed-console.xml

Cleanup pom.xml

Rename ObjectTree? to LocalTree? (also make LocalTree? and RemoteTree? final).

Minor change.

Add maximum number of columns in ListPanelProvider?.

Improve ColumnsConfig? interpretation.

Automatically fill FramsClass?.name if trying to construct empty.

Improve identitifer case mangling in XmlLoader?.

Introduce configurable ColumnsConfig?.

Draft working version of ListPanel?.

Table is being shown (although empty).

More improvements to table building.

Move some functionality from Frame to TreeModel?.

Move tree classes in gui to separate package.

Remove old table related classes.

Add draft implementation of TableModel?.

Redirect ParamBuilder?.forAccess to AccessInterface?.

Optimize ParamBuilder?.forAccess()

Do not clear list when loading.

Do not load fetched values directly.

Implement different AccessInterface? copying policy.

Optimize fetching values routine.

Remove Mode enum (work out get semantics).

Some improvements to ListChange? handling.

Improve UniqueListAccess?.

Add reaction for ListChanges? in the TreeNode?.

EventListeners? are being added in the TreeNode?.

Listeners for ListParams? are now very naive (they download
whole list).

Automatially register on events in GUI.

Events are working in RemoteTree? and Server.

Move listeners to the ClientSideManagedConnection?.

Remove old classes responsible for event subscriptions.

Improve event reading.

Improve events handling at server side.

Add register attribute in FramsClassAnnotation?
to automatically also register other classes.

Registering events works.

Setup for remote listeners registration.

More improvements.

Minor changes.

Add rootTree to the ClientAtServer?.

Moving CLI to the ClientAtServer?.

Fix bug: use Void.TYPE instead of Void.class

More development around CLI.

  • Improve Path resolving.

Add synthetic root to ObjectTree?.

It is needed to allow sybling for the original root
that would containg CLI.

Some work with registering events in RemoteTree?.

Draft implementation of listener registering in RemoteTree?.

Support events registration in the ObjectTree?.

Add events support to ReflectionAccess?.

EventParam? is recognized by ParamCandidate?.

Prepare interface for Events across project.

Add EventListener? and API for listeners in Tree.

File:
1 edited

Legend:

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

    r98 r99  
    22
    33import com.framsticks.communication.queries.ApplicationRequest;
     4import com.framsticks.communication.queries.CallRequest;
    45import com.framsticks.communication.queries.ProtocolRequest;
    5 import com.framsticks.communication.queries.RegistrationRequest;
     6import com.framsticks.communication.queries.RegisterRequest;
    67import com.framsticks.communication.queries.UseRequest;
    78import com.framsticks.communication.queries.VersionRequest;
    8 import com.framsticks.communication.util.LoggingStateCallback;
     9import com.framsticks.core.Path;
    910import com.framsticks.params.ListSource;
    1011import com.framsticks.util.*;
     
    1819import com.framsticks.util.lang.Pair;
    1920import com.framsticks.util.lang.Strings;
     21import com.framsticks.params.EventListener;
    2022
    2123import org.apache.log4j.Logger;
     
    3234        private final static Logger log = Logger.getLogger(ClientSideManagedConnection.class);
    3335
    34         protected final Map<String, Subscription<?>> subscriptions = new HashMap<>();
    35 
    3636        private final List<Runnable> applicationRequestsBuffer = new LinkedList<>();
    3737        private boolean isHandshakeDone = false;
     38
    3839
    3940        /**
     
    9394        }
    9495
    95         private static class EventFire extends InboundMessage {
    96                 public final Subscription<?> subscription;
    97 
    98                 private EventFire(Subscription<?> subscription) {
    99                         this.subscription = subscription;
    100                 }
    101 
    102                 public void startFile(String path) {
    103                         assert path == null;
    104                         initCurrentFile(null);
    105                 }
    106 
    107                 @Override
    108                 public void eof() {
    109                         finishCurrentFile();
    110 
    111                         subscription.dispatchCall(getFiles());
    112                 }
     96        protected List<String> readFileContent() {
     97                List<String> content = new LinkedList<String>();
     98                String line;
     99                while (!(line = getLine()).startsWith("eof")) {
     100                        content.add(line);
     101                }
     102                return content;
    113103        }
    114104
     
    239229        }
    240230
    241         public <C> void subscribe(final String path, final Dispatcher<C> dispatcher, final SubscriptionCallback<? extends C> callback) {
    242                 send(new RegistrationRequest().path(path), AtOnceDispatcher.getInstance(), new ClientSideResponseFuture(callback) {
    243                         @Override
    244                         protected void processOk(Response response) {
    245                                 assert response.getFiles().isEmpty();
    246                                 Subscription<C> subscription = new Subscription<C>(ClientSideManagedConnection.this, path, response.getComment(), dispatcher);
    247                                 log.debug("registered on event: " + subscription);
    248                                 synchronized (subscriptions) {
    249                                         subscriptions.put(subscription.getRegisteredPath(), subscription);
    250                                 }
    251                                 subscription.setEventCallback(callback.subscribed(subscription));
    252                                 if (subscription.getEventCallback() == null) {
    253                                         log.info("subscription for " + path + " aborted");
    254                                         subscription.unsubscribe(new LoggingStateCallback(log, "abort subscription"));
    255                                 }
    256                         }
    257                 });
    258         }
    259231
    260232        private void sendQueryVersion(final int version, final Future<Void> future) {
     
    322294                Matcher matcher = Request.EVENT_PATTERN.matcher(rest);
    323295                if (!matcher.matches()) {
    324                         log.error("invalid event line: " + rest);
    325                         return;
    326                 }
    327                 Subscription<?> subscription = subscriptions.get(matcher.group(1));
    328                 if (subscription == null) {
    329                         log.error("non subscribed event: " + matcher.group(1));
    330                         return;
    331                 }
    332                 EventFire event = new EventFire(subscription);
    333                 event.startFile(null);
    334                 processMessage(event);
     296                        throw new FramsticksException().msg("invalid event line").arg("rest", rest);
     297                }
     298                String fileLine = getLine();
     299                if (!fileLine.equals("file")) {
     300                        throw new FramsticksException().msg("expected file line").arg("got", fileLine);
     301                }
     302                String eventObjectPath = Request.takeGroup(rest, matcher, 1).toString();
     303                String eventCalleePath = Request.takeGroup(rest, matcher, 2).toString();
     304                final File file = new File("", new ListSource(readFileContent()));
     305                log.debug("firing event " + eventObjectPath);
     306                EventListener<File> listener;
     307                synchronized (registeredListeners) {
     308                        listener = registeredListeners.get(eventObjectPath);
     309                }
     310                if (listener  == null) {
     311                        throw new FramsticksException().msg("failed to find registered event").arg("event path", eventObjectPath).arg("object", eventCalleePath);
     312                }
     313                listener.action(file);
    335314        }
    336315
     
    397376        }
    398377
     378        protected final Map<String, EventListener<File>> registeredListeners = new HashMap<>();
     379
     380        public <C> void addListener(String path, final EventListener<File> listener, final Dispatcher<C> dispatcher, final Future<Void> future) {
     381                send(new RegisterRequest().path(path), dispatcher, new ClientSideResponseFuture(future) {
     382                        @Override
     383                        protected void processOk(Response response) {
     384                                synchronized (registeredListeners) {
     385                                        registeredListeners.put(Path.validateString(response.getComment()), listener);
     386                                }
     387                                future.pass(null);
     388                        }
     389                });
     390        }
     391
     392        public <C> void removeListener(EventListener<File> listener, final Dispatcher<C> dispatcher, final Future<Void> future) {
     393                String eventPath = null;
     394                synchronized (registeredListeners) {
     395                        for (Map.Entry<String, EventListener<File>> e : registeredListeners.entrySet()) {
     396                                if (e.getValue() == listener) {
     397                                        eventPath = e.getKey();
     398                                        break;
     399                                }
     400                        }
     401                }
     402                if (eventPath == null) {
     403                        future.handle(new FramsticksException().msg("listener is not registered").arg("listener", listener));
     404                        return;
     405                }
     406
     407                final String finalEventPath = eventPath;
     408                                //TODO add arguments to the exception
     409                send(new CallRequest().procedure("remove").path(eventPath), dispatcher, new ClientSideResponseFuture(future) {
     410
     411                        @Override
     412                        protected void processOk(Response response) {
     413                                synchronized (registeredListeners) {
     414                                        registeredListeners.remove(finalEventPath);
     415                                }
     416                                future.pass(null);
     417                        }
     418                });
     419        }
    399420}
Note: See TracChangeset for help on using the changeset viewer.