Exemplo n.º 1
0
  protected void handleView(View view) {
    this.view = view;
    if (log.isDebugEnabled()) log.debug("view=" + view);
    List<Address> members = view.getMembers();

    _consumerLock.lock();
    try {
      // This removes the consumers that were registered that are now gone
      Iterator<Owner> iterator = _consumersAvailable.iterator();
      while (iterator.hasNext()) {
        Owner owner = iterator.next();
        if (!members.contains(owner.getAddress())) {
          iterator.remove();
          sendRemoveConsumerRequest(owner);
        }
      }

      // This removes the tasks that those requestors are gone
      iterator = _runRequests.iterator();
      while (iterator.hasNext()) {
        Owner owner = iterator.next();
        if (!members.contains(owner.getAddress())) {
          iterator.remove();
          sendRemoveRunRequest(owner);
        }
      }

      synchronized (_awaitingReturn) {
        for (Entry<Owner, Runnable> entry : _awaitingReturn.entrySet()) {
          // The person currently servicing our request has gone down
          // without completing so we have to keep our request alive by
          // sending ours back to the coordinator
          Owner owner = entry.getKey();
          if (!members.contains(owner.getAddress())) {
            Runnable runnable = entry.getValue();
            // We need to register the request id before sending the request back to the coordinator
            // in case if our task gets picked up since another was removed
            _requestId.put(runnable, owner.getRequestId());
            _awaitingConsumer.add(runnable);
            sendToCoordinator(RUN_REQUEST, owner.getRequestId(), local_addr);
          }
        }
      }
    } finally {
      _consumerLock.unlock();
    }
  }
Exemplo n.º 2
0
  protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
      case PROMPT_OAUTH:
        builder
            .setMessage(R.string.commentneedsinaoauth)
            .setCancelable(false)
            .setPositiveButton(
                R.string.ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                    FlipdroidApplications application = (FlipdroidApplications) getApplication();
                    OAuth oauth = new OAuth();
                    application.setOauth(oauth);
                    //// System.out.println("OAuthHolder.oauth" + application + oauth);
                    oauth.RequestAccessToken(PageActivity.this, "flipdroid://SinaAccountSaver");
                  }
                })
            .setNegativeButton(
                R.string.cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {}
                });
        this.dialog = builder.create();
        break;
      case NAVIGATION:
        LayoutInflater li = LayoutInflater.from(this);
        View v = li.inflate(R.layout.dialog_nav_title_view, null);

        // builder.setView(v);
        builder.setCustomTitle(v);

        builder.setAdapter(
            sourceAdapter,
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(PageActivity.this, PageActivity.class);
                SourceItem cursor = sourceAdapter.getItem(i);
                intent.putExtra("type", cursor.getSourceType());
                intent.putExtra("sourceId", cursor.getSourceId());
                intent.putExtra("sourceImage", cursor.getSourceImage());
                intent.putExtra("sourceName", cursor.getSourceName());
                intent.putExtra("contentUrl", cursor.getSourceURL());
                if (dialog != null) dialog.dismiss();
                startActivity(intent);
                finishActivity();
              }
            });

        this.dialog = builder.create();
        Button btn_addshortcut = (Button) v.findViewById(R.id.btnaddshortcut);
        btn_addshortcut.setText("add shortcut");

        btn_addshortcut.setOnClickListener(
            new Button.OnClickListener() {
              public void onClick(View v) {
                addShortcut();
                dialog.cancel();
              }
            });

        dialog.setOnKeyListener(
            new DialogInterface.OnKeyListener() {
              public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_MENU) {
                  if (dialog != null) {
                    dialog.dismiss();
                    return true;
                  }
                }

                return false;
              }
            });
        break;
      default:
        this.dialog = null;
    }
    if (dialog != null) {
      dialog.setOnDismissListener(
          new DialogInterface.OnDismissListener() {
            public void onDismiss(DialogInterface dialogInterface) {
              dialog = null;
            }
          });
    }
    return this.dialog;
  }
Exemplo n.º 3
0
 @ManagedAttribute
 public String getView() {
   return view != null ? view.toString() : null;
 }