/** @author zobo */
public class UpdateSphereEmailsHandler extends AbstractOldActionBuilder {

  @SuppressWarnings("unused")
  private static final org.apache.log4j.Logger logger =
      ss.global.SSLogger.getLogger(UpdateSphereEmailsHandler.class);

  private final DialogsMainCli cli;

  public UpdateSphereEmailsHandler(DialogsMainCli cli) {
    this.cli = cli;
  }

  public String getProtocol() {
    return SSProtocolConstants.UPDATE_SPHERES_EMAILS;
  }

  @SuppressWarnings("unchecked")
  public void handleUpdateSphereEmails(final SphereEmail sphereEmail) {
    Hashtable update = new Hashtable();
    update.put(SC.SPHERES_EMAIS, sphereEmail.getEmailNames().getSingleStringEmails());
    update.put(SC.SPHERE_ID, sphereEmail.getSphereId());
    update.put(SC.SPHERE_EMAILS_ENABLED, new Boolean(sphereEmail.getEnabled()));
    update.put(SC.ADD_ROUTING_DEFAULT, new Boolean(sphereEmail.getIsMessageIdAdd()));
    update.put(SessionConstants.PROTOCOL, SSProtocolConstants.UPDATE_SPHERES_EMAILS);
    this.cli.sendFromQueue(update);
  }
}
/** @author zobo */
public class EmailControlPanelComposeListener implements SelectionListener {

  private static final Logger logger = SSLogger.getLogger(EmailControlPanelComposeListener.class);

  private MessagesPane mb = null;

  private Hashtable session;

  public EmailControlPanelComposeListener(MessagesPane mb, Hashtable session) {
    super();
    this.mb = mb;
    this.session = session;
  }

  public void widgetSelected(SelectionEvent arg0) {
    logger.info("Clicked item Compose Email");
    (new EmailController(this.mb, this.session)).clickedComposeEmail(null);
  }

  public void widgetDefaultSelected(SelectionEvent arg0) {}
}
/** @author zobo */
public class NewContactConnectActionListener implements Listener {
  private NewContact newContact;
  private Logger logger = SSLogger.getLogger(this.getClass());

  /** @param newContact */
  public NewContactConnectActionListener(NewContact newContact) {
    super();
    this.newContact = newContact;
  }

  public void handleEvent(Event event) {
    String sphereURL =
        this.newContact
            .getOrigDoc()
            .getRootElement()
            .element("home_sphere")
            .attributeValue("value");

    this.logger.info("Sphere URL : " + sphereURL);
    try {
      String reciprocalLogin =
          this.newContact
              .getOrigDoc()
              .getRootElement()
              .element("reciprocal_login")
              .attributeValue("value");
      String cname = NameTranslation.createContactNameFromContactDoc(this.newContact.getOrigDoc());
      String systemName = this.newContact.getClient().getVerifyAuth().getSystemName(cname);

      SupraSphereFrame.INSTANCE.startConnection(
          null, this.newContact.getSession(), sphereURL, reciprocalLogin, systemName);

    } catch (NullPointerException npe) {

    }

    NewContact.getSShell().dispose();
  }
}
/**
 * @deprecated
 * @author dankosedin
 *     <p>TODO:#member-refactoring Not used. Previosly used in ss.client.ui.viewer.NewSphere //
 *     mp.client.publishTerse(session,doc); //
 *     mp.client.registerSphereWithMembers(registermembers,doc.getRootElement().attributeValue("system_name"),doc.getRootElement().attributeValue("display_name"));
 *     <p>NewSphere.this.mp.client.openSphereForMembers( called XmldbUtils.registerSphereWithMembers
 *     but this method also called by OpenSphereForMembersHandler
 */
public class RegisterSphereWithMembersHandlerClient implements ProtocolHandler {

  private DialogsMainCli cli;

  @SuppressWarnings("unused")
  private static final org.apache.log4j.Logger logger =
      ss.global.SSLogger.getLogger(RegisterSphereWithMembersHandlerClient.class);

  /**
   * @deprecated
   * @param cli
   */
  public RegisterSphereWithMembersHandlerClient(DialogsMainCli cli) {
    this.cli = cli;
  }

  public String getProtocol() {
    return SSProtocolConstants.REGISTER_SPHERE_WITH_MEMBERS;
  }

  public void handle(Hashtable update) {
    // to-server-only handler
  }

  @SuppressWarnings("unchecked")
  public void registerSphereWithMembers(Vector members, String system_name, String display_name) {
    Hashtable toSend = (Hashtable) this.cli.session.clone();
    toSend.remove(SessionConstants.PASSPHRASE);
    Hashtable update = new Hashtable();
    update.put(SessionConstants.PROTOCOL, SSProtocolConstants.REGISTER_SPHERE_WITH_MEMBERS);

    update.put(SessionConstants.MEMBERS, members);
    update.put(SessionConstants.SYSTEM_NAME, system_name); // RC
    update.put(SessionConstants.DISPLAY_NAME, display_name);
    update.put(SessionConstants.SESSION, toSend);
    this.cli.sendFromQueue(update);
  }
}
public class GetPrivateDomainNamesHandler
    extends AbstractGetterCommandHandler<GetPrivateDomainNamesCommand, Vector<String>> {

  private static final org.apache.log4j.Logger logger =
      ss.global.SSLogger.getLogger(GetPrivateDomainNamesHandler.class);

  /** @param peer */
  public GetPrivateDomainNamesHandler(DialogsMainPeer peer) {
    super(GetPrivateDomainNamesCommand.class, peer);
  }

  private static final String HTTP_PATTERN =
      "(http:\\/\\/([\\w-]+\\.)+[\\w-]+)(\\/[\\w- .\\/?%=]*)?";

  private static final String WWW_PATTERN = "(www\\.([\\w-]+\\.)+[\\w-]+)(\\/[\\w- .\\/?%=]*)?";

  /* (non-Javadoc)
   * @see ss.common.networking2.RespondentCommandHandler#evaluate(ss.common.networking2.Command)
   */
  @Override
  protected Vector<String> evaluate(GetPrivateDomainNamesCommand command)
      throws CommandHandleException {
    String filter = command.getStringArg(SC.FILTER);
    String loginName = (String) (command.getSessionArg()).get(SC.USERNAME);
    String homeSphereId = this.peer.getVerifyAuth().getPersonalSphereFromLogin(loginName);
    logger.info("sphere=" + homeSphereId);
    logger.info("filter=" + filter);
    Vector<Document> filteredBookmarks =
        this.peer.getXmldb().getBookmarksForHomeSphere(homeSphereId, filter.toLowerCase());

    Vector<String> domains = new Vector<String>();
    for (Document doc : filteredBookmarks) {
      String url = doc.getRootElement().element("address").attributeValue("value");
      logger.info("url=" + url);
      String domain = getDomain(url);
      if ((domain != null) && !VariousUtils.vectorContains(domain, domains)) {
        domains.add(domain);
      }
    }
    return domains;
  }

  private String getDomain(String url) {
    PatternMatcher matcher = new Perl5Matcher();
    PatternCompiler compiler = new Perl5Compiler();
    PatternMatcherInput input = new PatternMatcherInput(url);
    Pattern pattern = null;

    String patternString = HTTP_PATTERN;
    try {
      pattern = compiler.compile(patternString);
    } catch (MalformedPatternException e) {
      logger.error("Incorrect pattern: " + patternString, e);
    }
    while (matcher.contains(input, pattern)) {
      MatchResult result = matcher.getMatch();
      String sResult = result.group(1);
      logger.info("Match: " + sResult);
      return sResult;
    }
    patternString = WWW_PATTERN;
    try {
      pattern = compiler.compile(patternString);
    } catch (MalformedPatternException e) {
      logger.error("Incorrect pattern: " + patternString, e);
    }
    while (matcher.contains(input, pattern)) {
      MatchResult result = matcher.getMatch();
      String sResult = result.group(1);
      logger.info("Match: " + sResult);
      return sResult;
    }
    return null;
  }
}
public class SupraSphereShellController {

  @SuppressWarnings("unused")
  private static final org.apache.log4j.Logger logger =
      ss.global.SSLogger.getLogger(SupraSphereShellController.class);

  private final SupraSphereFrame supra;

  private final ShellListener shellListener;

  private Shell shell;

  public SupraSphereShellController(SupraSphereFrame supraFrame) {
    super();
    this.supra = supraFrame;
    this.shellListener = new SupraFrameShellListener();
  }

  public void init(Shell supraFrameShell) {
    this.shell = supraFrameShell;
    //        String fsep = System.getProperty("file.separator");
    //        String bdir = System.getProperty("user.dir");
    try {
      Image im;
      im =
          new Image(
              Display.getDefault(), getClass().getResource(ImagesPaths.SUPRA_ICON).openStream());
      this.shell.setImage(im);
    } catch (IOException ex) {
      logger.error("can't create supra icon", ex);
    }

    setupListeners();
  }

  /** @author roman */
  private final class SupraFrameShellListener extends ShellAdapter {
    private SupraSphereShellController shellController = SupraSphereShellController.this;

    public void shellMinimized(ShellEvent e) {

      logger.info("IT minimized here");

      this.shellController.supra.getTrayItem().setBlinkPossible(true);
    }

    public void shellClosed(ShellEvent e) {
      e.doit = false;
      UiUtils.swtBeginInvoke(
          new Runnable() {
            private SupraSphereShellController shellController = SupraSphereShellController.this;

            public void run() {
              new ExitDialog(this.shellController.supra);
            }
          });
    }

    public void shellIconified(ShellEvent e) {

      BalloonsController.INSTANCE.setShown(false);
    }

    public void shellDeiconified(ShellEvent e) {

      BalloonsController.INSTANCE.setShown(true);

      this.shellController.supra.getTrayItem().endBlink();
    }

    public void shellDeactivated(ShellEvent e) {
      // logger.info("deactivated");
      this.shellController.supra.getTrayItem().setBlinkPossible(true);
      /*
       * if (bw!=null) { bw.showOrHide(false); }
       */

    }

    public void shellActivated(ShellEvent e) {
      if (this.shellController.supra.tabbedPane != null) {
        if (this.shellController.supra.getShell().isFocusControl()) {
          this.shellController.supra.setFocusToSendField();
        }
      }
      this.shellController.supra.getTrayItem().setBlinkPossible(false);
      this.shellController.supra.getTrayItem().endBlink();
    }

    public void shellResized(ShellEvent e) {}

    public void shellMaximized(ShellEvent e) {
      logger.info("IT MAXIMIZED here");
      this.shellController.supra.getTrayItem().endBlink();
    }
  }

  /** */
  private void setupListeners() {
    this.shell.addMouseListener(
        new MouseListener() {

          private SupraSphereShellController shell = SupraSphereShellController.this;

          public void mouseDoubleClick(MouseEvent arg0) {
            this.shell.supra.getTrayItem().endBlink();
          }

          public void mouseDown(MouseEvent arg0) {
            this.shell.supra.getTrayItem().endBlink();
          }

          public void mouseUp(MouseEvent arg0) {
            this.shell.supra.getTrayItem().endBlink();
          }
        });

    this.shell.addControlListener(
        new ControlAdapter() {
          // private SupraSphereShellController shellController = SupraSphereShellController.this;

          public void controlResized(ControlEvent e) {

            // mainEmbedComp.setBounds(mainEmbedComp.getClientArea());
            // shell was maximized so undo it
            /*if (this.shellController.shell.getMaximized()) {
                logger.info("IT MAXIMIZED");

            }
            logger.warn("E SOURCDE: " + e.getSource());
            if (this.shellController.shell.getMinimized()) {
                logger.warn("IT MINIMIZED");

            }
            */

          }
        });

    this.shell.addFocusListener(
        new FocusListener() {

          private SupraSphereShellController shellController = SupraSphereShellController.this;

          public void focusGained(FocusEvent e) {

            if (this.shellController.supra.tabbedPane != null) {
              this.shellController.supra.setFocusToSendField();
            }

            this.shellController.supra.getTrayItem().setBlinkPossible(false);
            this.shellController.supra.getTrayItem().endBlink();
          }

          public void focusLost(FocusEvent e) {

            this.shellController.supra.getTrayItem().setBlinkPossible(true);
          }
        });
  }

  /** @return the shellListener */
  public ShellListener getShellListener() {
    return this.shellListener;
  }
}
/** @author dankosedin */
public class GetRecentQueries {

  @SuppressWarnings("unused")
  private static final org.apache.log4j.Logger logger =
      ss.global.SSLogger.getLogger(GetRecentQueries.class);

  private static final String RESPONSE_ID = "response_id";

  private static final String LAST_UPDATED = "last_updated";

  private static final String MOMENT = "moment";

  private static final String CURRENT_SPHERE = "current_sphere";

  private static final String CONFIRMED = "confirmed";

  private static final String STATUS = "status";

  private static final String MESSAGE_ID = "message_id";

  private static final String THREAD_TYPE = "thread_type";

  private static final String KEYWORDS = "keywords";

  private static final String TYPE = "type";

  private static final String GIVER = "giver";

  private static final String VALUE = "value";

  private final DialogsMainCli cli;

  public GetRecentQueries(DialogsMainCli cli) {
    this.cli = cli;
  }

  @SuppressWarnings("unchecked")
  private void preprocessQueries(Vector<Element> queries, String messageId, String localSphereId) {
    for (Element query : queries) {
      String subject = query.attributeValue(VALUE);
      Document genericDoc = GenericXMLDocument.XMLDoc(subject, "", query.attributeValue(GIVER));
      genericDoc.getRootElement().addElement(TYPE).addAttribute(VALUE, KEYWORDS);
      genericDoc.getRootElement().addElement(THREAD_TYPE).addAttribute(VALUE, KEYWORDS);
      genericDoc
          .getRootElement()
          .addElement(MESSAGE_ID)
          .addAttribute(VALUE, new Long(GenericXMLDocument.getNextTableId()).toString());
      genericDoc.getRootElement().addElement(STATUS).addAttribute(VALUE, CONFIRMED);
      genericDoc.getRootElement().addElement(CONFIRMED).addAttribute(VALUE, "true");
      genericDoc
          .getRootElement()
          .addElement(CURRENT_SPHERE)
          .addAttribute(VALUE, (String) this.cli.session.get(SessionConstants.SPHERE_ID2));
      String moment = query.attributeValue(MOMENT);
      if (moment == null) {
        Date current = new Date();
        moment =
            DateFormat.getTimeInstance(DateFormat.LONG).format(current)
                + " "
                + DateFormat.getDateInstance(DateFormat.MEDIUM).format(current);
      }
      genericDoc.getRootElement().addElement(MOMENT).addAttribute(VALUE, moment);
      genericDoc.getRootElement().addElement(LAST_UPDATED).addAttribute(VALUE, moment);
      genericDoc.getRootElement().addElement(RESPONSE_ID).addAttribute(VALUE, messageId);
      if (logger.isDebugEnabled()) {
        logger.debug("doc : " + XmlDocumentUtils.toPrettyString(genericDoc));
      }
      Hashtable newUpdate = new Hashtable();
      newUpdate.put(SessionConstants.DOCUMENT, genericDoc);
      newUpdate.put(SessionConstants.SPHERE, localSphereId);
      newUpdate.put(SessionConstants.IS_UPDATE, "true");
      this.cli.callInsert(new PostponedUpdate(newUpdate));
    }
  }

  @SuppressWarnings("unchecked")
  public Vector getRecentQueries(
      Hashtable session, String homeSphereId, String homeMessageId, String localSphereId) {
    logger.info(
        "Start recentqueires: " + homeSphereId + " : " + homeMessageId + " : " + localSphereId);
    GetRecentQueriesCommand command = new GetRecentQueriesCommand();
    command.putSessionArg(session);
    command.putArg(SessionConstants.HOME_SPHERE_ID, homeSphereId);
    command.putArg(SessionConstants.HOME_MESSAGE_ID, homeMessageId);
    Vector<Element> queries = command.execute(this.cli, Vector.class);
    preprocessQueries(queries, homeMessageId, localSphereId);
    return queries;
  }
}
public final class ApplicationUpdater {

  @SuppressWarnings("unused")
  private static org.apache.log4j.Logger logger =
      ss.global.SSLogger.getLogger(ApplicationUpdater.class);

  private final InstallationDescriptionManager installationDescriptionManager =
      InstallationDescriptionManager.INSTANCE;

  private final String applicationFolder;

  private final UpdateProcessListener updateProcessListener;

  private final IUpdateProtocolFactory protocolFactory;

  private final IFilesDownloader filesDownloader;

  private boolean actualClientCanWorkWithServer = false;

  /**
   * @param updateResultListener
   * @param protocolFactory
   * @param filesDownloader
   */
  public ApplicationUpdater(
      UpdateProcessListener updateProcessListener,
      IUpdateProtocolFactory protocolFactory,
      IFilesDownloader filesDownloader) {
    super();
    if (updateProcessListener == null) {
      throw new ArgumentNullPointerException("updateProcessListener");
    }
    if (protocolFactory == null) {
      throw new ArgumentNullPointerException("protocolFactory");
    }
    if (filesDownloader == null) {
      throw new ArgumentNullPointerException("filesDownloader");
    }
    this.updateProcessListener = updateProcessListener;
    this.protocolFactory = protocolFactory;
    this.filesDownloader = filesDownloader;
    this.applicationFolder = FolderUtils.getApplicationFolder();
    if (this.applicationFolder == null) {
      throw new NullPointerException("Application folder is null");
    }
  }

  public void start() {
    ThreadUtils.start(
        new Runnable() {
          public void run() {
            safeUpdate();
          }
        },
        getClass());
  }

  void safeUpdate() {
    try {
      update();
    } catch (CantCreateUpdateProtocolException ex) {
      logger.error("Cant update application. Continue normal run", ex);
      continueApplictionIsUpToDate();
    } catch (CantUpdateApplicationException ex) {
      final String message = DebugUtils.toSignificantMessage(ex);
      logger.error(message, ex);
      cantUpdate(message);
    } catch (Throwable ex) {
      final String message = "Unexpected update error: " + DebugUtils.toSignificantMessage(ex);
      logger.error(message, ex);
      cantUpdate(message);
    }
  }
  /**
   * @param runnable
   * @throws IOException
   * @throws CommandExecuteException
   * @throws CantUpdateApplicationException
   */
  void update() throws CantUpdateApplicationException {
    final InstallationDescription localInstallationDescription = getLocalInstallationDescription();
    final UpdateResponse serverResponse =
        getServerResponse(localInstallationDescription.getApplicationVersionObj());
    this.actualClientCanWorkWithServer = serverResponse.isActualClientCanWorkWithServer();
    if (serverResponse.getInstallationStatus() == InstallationStatus.UP_TO_DATE) {
      continueApplictionIsUpToDate();
    } else if (serverResponse.getInstallationStatus() == InstallationStatus.OUT_OF_DATE) {
      runUpdate(localInstallationDescription, serverResponse.getInstallationDescription());
    } else if (serverResponse.getInstallationStatus() == InstallationStatus.UNKNOWN) {
      logger.warn(
          "Cant update application server response is unknown. Cause: "
              + serverResponse.getMessage());
      if (serverResponse.isActualClientCanWorkWithServer()) {
        continueApplictionIsUpToDate();
      } else {
        cantUpdate(serverResponse.getMessage());
      }
    } else {
      cantUpdate(serverResponse.getMessage());
    }
  }

  /** @param message */
  private void cantUpdate(String message) {
    try {
      this.updateProcessListener.cantUpdate(message, this.actualClientCanWorkWithServer);
    } catch (Throwable ex) {
      logger.error("Can't notify about update fails: " + message, ex);
    }
  }

  /**
   * @param message
   * @param installationDescription
   * @param description
   * @throws CantUpdateApplicationException
   */
  private void runUpdate(InstallationDescription current, InstallationDescription target)
      throws CantUpdateApplicationException {
    if (!askUserToProceed()) {
      this.cantUpdate("You can't login with old application version.");
    } else {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Create update builder from "
                + current.getApplicationVersionObj()
                + " to "
                + target.getApplicationVersionObj());
      }
      final UpdateBuilder builder = new UpdateBuilder(current, target);
      final Update update = builder.getResult();
      if (logger.isDebugEnabled()) {
        logger.debug("Update created " + update);
      }
      UpdateResult result = update.perform(this.filesDownloader);
      this.updateProcessListener.updated(result);
    }
  }

  /** @return */
  private boolean askUserToProceed() {
    return this.updateProcessListener.askUserToProceedUpdate();
  }

  /** */
  private void continueApplictionIsUpToDate() {
    this.updateProcessListener.applicationIsUpToDate();
  }

  /**
   * @param applicationVersionObj
   * @return
   */
  private UpdateResponse getServerResponse(QualifiedVersion applicationVersionObj)
      throws CantUpdateApplicationException {
    final Protocol protocol = this.protocolFactory.create();
    try {
      protocol.start(ClientProtocolManager.INSTANCE);
      final UpdateHelloCommand helloCommand = new UpdateHelloCommand(applicationVersionObj);
      final UpdateResponse response = helloCommand.execute(protocol, UpdateResponse.class);
      if (response == null) {
        throw new CantUpdateApplicationException("Update response is null");
      }
      return response;
    } catch (CommandExecuteException ex) {
      throw new CantUpdateApplicationException("Can't fetch update response", ex);
    } finally {
      protocol.beginClose();
    }
  }

  /** */
  private InstallationDescription getLocalInstallationDescription() {
    if (this.installationDescriptionManager.hasInstallationDescription(this.applicationFolder)) {
      try {
        final InstallationDescription description =
            this.installationDescriptionManager.loadFromApplicationFolder(this.applicationFolder);
        description.verifyAndFixOsName();
        return description;
      } catch (CantLoadInstallationDescriptionException ex) {
        logger.error("Can't load application description. Try to generate it", ex);
      }
    } else {
      logger.warn("Can' find application description. Try to generate it");
    }
    final InstallationDescription blank = this.installationDescriptionManager.createBlank();
    try {
      this.installationDescriptionManager.saveToApplicationFolder(this.applicationFolder, blank);
    } catch (CantSaveInstallationDescriptionException ex) {
      logger.error("Can't save application installation description", ex);
    }
    return blank;
  }
}
Beispiel #9
0
/** @author zobo */
public class Deliverer {

  private class BlockedPane {
    MessagesPane pane = null;

    private LinkedList<AbstractDeliveringElement> blockedList =
        new LinkedList<AbstractDeliveringElement>();

    public BlockedPane(MessagesPane specificPane) {
      this.pane = specificPane;
    }

    void put(AbstractDeliveringElement element) {
      this.blockedList.offer(element);
    }

    LinkedList<AbstractDeliveringElement> get() {
      return this.blockedList;
    }
  }

  @SuppressWarnings("unused")
  private static final org.apache.log4j.Logger logger =
      ss.global.SSLogger.getLogger(Deliverer.class);

  private final List<MessagesPane> panes;

  private final List<BlockedPane> blockedPanes;

  private final String sphereId;

  private final Thread deliver;

  private final MessagesLine messagesQueue;

  private boolean blocked = true;

  private boolean alive = true;

  Deliverer(String sphereId) {
    if (logger.isDebugEnabled()) {
      logger.debug("Deliverer started for: " + sphereId);
    }
    this.sphereId = sphereId;
    this.panes = new ArrayList<MessagesPane>();
    this.messagesQueue = new MessagesLine();
    this.blockedPanes = new ArrayList<BlockedPane>();
    this.deliver =
        new Thread() {
          @Override
          public void run() {
            while (Deliverer.this.alive) {
              if (Deliverer.this.blocked) {
                try {
                  sleep(100);
                } catch (InterruptedException ex) {
                  logger.error("Interrupted");
                }
              } else {
                processNext();
              }
            }
          }
        };
    ThreadUtils.startDemon(this.deliver, "Messages deliverer for sphereId: " + sphereId);
  }

  private void processNext() {

    AbstractDeliveringElement element = this.messagesQueue.take();
    List<MessagesPane> localPanes = null;
    AtomicReference<LinkedList<AbstractDeliveringElement>> releasedList =
        new AtomicReference<LinkedList<AbstractDeliveringElement>>();
    synchronized (this.panes) {
      localPanes = getPanes(element, releasedList);
    }
    if (releasedList.get() == null) {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Suggesting to pocessing element " + DeliverersManager.FACTORY.getLogInfo(element));
      }
      DeliverProcessor.process(element, localPanes);
    } else {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Processing with released list element "
                + DeliverersManager.FACTORY.getLogInfo(element));
      }
      DeliverProcessor.process(element, localPanes);
      for (AbstractDeliveringElement el : releasedList.get()) {
        if (logger.isDebugEnabled()) {
          logger.debug(
              "Processing as element from release list element "
                  + DeliverersManager.FACTORY.getLogInfo(el));
        }
        DeliverProcessor.process(el, localPanes);
      }
    }
  }

  private ArrayList<MessagesPane> getPanes(
      final AbstractDeliveringElement element,
      final AtomicReference<LinkedList<AbstractDeliveringElement>> releasedList) {
    if (element.getSpecific() != null) {
      ArrayList<MessagesPane> toRet = new ArrayList<MessagesPane>();
      if (isMessagesPane(element.getSpecific())) {
        synchronized (this.blockedPanes) {
          BlockedPane blockedPane = releaseBlocked(element.getSpecific());
          toRet.add(element.getSpecific());
          if (blockedPane != null) {
            if (logger.isDebugEnabled()) {
              logger.debug("Setting release list size: " + blockedPane.get().size());
            }
            releasedList.set(blockedPane.get());
          }
        }
      }
      return toRet;
    } else {
      synchronized (this.blockedPanes) {
        if (this.blockedPanes.isEmpty()) {
          return new ArrayList<MessagesPane>(this.panes);
        } else {
          ArrayList<MessagesPane> toRet = new ArrayList<MessagesPane>();
          for (MessagesPane pane : this.panes) {
            if (!processIsBlocked(element, pane)) {
              toRet.add(pane);
            }
          }
          return toRet;
        }
      }
    }
  }

  /** @param specific */
  private BlockedPane releaseBlocked(MessagesPane specific) {
    BlockedPane toDel = null;
    for (BlockedPane bpane : this.blockedPanes) {
      if (bpane.pane == specific) {
        toDel = bpane;
        break;
      }
    }
    if (toDel != null) {
      this.blockedPanes.remove(toDel);
    }
    return toDel;
  }

  private boolean processIsBlocked(AbstractDeliveringElement element, MessagesPane pane) {
    for (BlockedPane blockedPane : this.blockedPanes) {
      if (blockedPane.pane == pane) {
        if (logger.isDebugEnabled()) {
          logger.debug("Adding to block list " + DeliverersManager.FACTORY.getLogInfo(element));
        }
        blockedPane.put(element);
        return true;
      }
    }
    return false;
  }

  void deliver(AbstractDeliveringElement element) {
    this.messagesQueue.put(element);
  }

  void stop() {
    this.deliver.interrupt();
  }

  /** @param pane */
  void addMessagesPane(MessagesPane pane) {
    synchronized (this.panes) {
      if (pane != null) {
        this.panes.add(pane);
        if (this.blocked) {
          this.blocked = false;
        }
      }
    }
  }

  void removeMessagesPane(MessagesPane pane) {
    synchronized (this.panes) {
      if (pane != null) {
        this.panes.remove(pane);
      }
    }
  }

  String getSphereId() {
    return this.sphereId;
  }

  boolean isEmptyMessagesPanes() {
    return this.panes.isEmpty();
  }

  /** @param pane */
  boolean isMessagesPane(MessagesPane pane1) {
    synchronized (this.panes) {
      for (MessagesPane pane : this.panes) {
        if (pane == pane1) {
          return true;
        }
      }
      return false;
    }
  }

  /**
   * @param element
   * @param pane
   */
  void deliver(AbstractDeliveringElement element, MessagesPane pane) {
    synchronized (this.blockedPanes) {
      element.setSpecific(pane);
      this.messagesQueue.put(element);
    }
  }

  /** @param specificPane */
  void block(MessagesPane specificPane) {
    synchronized (this.blockedPanes) {
      BlockedPane p = new BlockedPane(specificPane);
      this.blockedPanes.add(p);
    }
  }

  /** */
  void kill() {
    this.alive = false;
    this.deliver.interrupt();
  }
}