Android Open Source - Soutils Soutils Observable






From Project

Back to project page Soutils.

License

The source code is released under:

MIT License

If you think the Android project Soutils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* The MIT License (MIT)
//  w  w  w .  j  a v  a  2s  .c o m
Copyright (c) 2012 Jerome Wagener

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/

package com.jeromewagener.soutils.messaging;

import java.util.ArrayList;
import java.util.List;

/** A SoutilsObservable is thread which is wrapped with network specific functionality provided by Soutils.
 * Using SoutilsObservers, these threads can be observed which will inform the SoutilsObservables
 * about various events. (E.g. the reception of messages) */
public abstract class SoutilsObservable extends Thread {
  /** A list of all Soutils observers that are observing the current thread. 
   * There will always be at least one observer per thread! */
  private List<SoutilsObserver> soutilsObservers = new ArrayList<SoutilsObserver>();
  
  /** Registers an observer which is notified about different events. (E.g. if a message arrives)
   * @param soutilsObserver the observer that should be registered */
  public void registerSoutilsObserver(SoutilsObserver soutilsObserver) {
    soutilsObservers.add(soutilsObserver);
  }

  /** Removes a specified observer
   * @param the observer to be removed */
  public void removeSoutilsObserver(SoutilsObserver soutilsObserver) {
    soutilsObservers.remove(soutilsObserver);
  }
  
  /** Returns a list of all registered observers */
  public List<SoutilsObserver> getSoutilsObservers() {
    return soutilsObservers;
  }
  
  /** Notifies all registered observers about an event that has arrived. 
   * This event is wrapped by a given SoutilsMessage */
  public void notifyAllObservers(SoutilsMessage soutilsMessage) {
    for (SoutilsObserver soutilsObserver : soutilsObservers) {
      soutilsObserver.handleSoutilsMessage(soutilsMessage);
    }
  }
}




Java Source Code List

com.jeromewagener.soutils.Parameters.java
com.jeromewagener.soutils.android.demo.ActivityHelpers.java
com.jeromewagener.soutils.android.demo.DemoActivity.java
com.jeromewagener.soutils.beaconing.BeaconReceiver.java
com.jeromewagener.soutils.beaconing.BeaconSenderAndReceiver.java
com.jeromewagener.soutils.beaconing.BeaconSender.java
com.jeromewagener.soutils.beaconing.package-info.java
com.jeromewagener.soutils.communication.CommunicationException.java
com.jeromewagener.soutils.communication.CommunicationManager.java
com.jeromewagener.soutils.communication.Communication.java
com.jeromewagener.soutils.communication.package-info.java
com.jeromewagener.soutils.demo.desktop.DemoApp.java
com.jeromewagener.soutils.demo.desktop.DemoHelper.java
com.jeromewagener.soutils.filetransfer.FileTransferClient.java
com.jeromewagener.soutils.filetransfer.FileTransferServer.java
com.jeromewagener.soutils.filetransfer.package-info.java
com.jeromewagener.soutils.messaging.MessageType.java
com.jeromewagener.soutils.messaging.SoutilsMessage.java
com.jeromewagener.soutils.messaging.SoutilsObservable.java
com.jeromewagener.soutils.messaging.SoutilsObserver.java
com.jeromewagener.soutils.messaging.package-info.java
com.jeromewagener.soutils.utilities.InetAddressUtilities.java
com.jeromewagener.soutils.utilities.Soutilities.java
com.jeromewagener.soutils.utilities.package-info.java
com.jeromewagener.soutils.package-info.java