Package com.ngt.jopenmetaverse.shared.sim.events

Examples of com.ngt.jopenmetaverse.shared.sim.events.AutoResetEvent


    IBitmap[] bitmaps = new IBitmap[textureIds.length];
    final AssetTexture[] result = new AssetTexture[1];
    for(int i=0; i < textureIds.length; i++)
    {

      AutoResetEvent textureDone = new AutoResetEvent(false);
      //Download the texture image
      Client.assets.RequestImage(textureIds[i], TextureDownloadCallback(result, textureDone));
      //wait for 1 min
      textureDone.waitOne(60 * 1000);
      if(result[0] != null)
      {
        //Decode the jpeg2000 image
        IOpenJPEG openJpeg = OpenJPEGFactory.getIntance();
        bitmaps[i] = openJpeg.DecodeToIBitMap(result[0].AssetData);
View Full Code Here


      else
        return null;
    }
    else
    { // Mesh
      final AutoResetEvent gotMesh = new AutoResetEvent(false);
      final FacetedMesh[] tmpMesh = new FacetedMesh[1]
      client.assets.RequestMesh(prim.Sculpt.SculptTexture, new MethodDelegate<Void, MeshDownloadCallbackArgs>()
          {
        public Void execute(MeshDownloadCallbackArgs e) {
          if (!e.isSuccess() || !FacetedMesh.TryDecodeFromAsset(prim, e.getAssetMesh(), MeshRenderDetail, tmpMesh))
          {
            JLogger.warn("Failed to fetch or decode the mesh asset");
          }
          gotMesh.set();               
          return null;
        }
          });
      mesh =  tmpMesh[0];
      gotMesh.waitOne(20 * 1000);
    }
    return mesh;
      }
View Full Code Here

  /// Blocking method to populate the Wearables dictionary
  /// </summary>
  /// <returns>True on success, otherwise false</returns>
  boolean GetAgentWearables() throws InterruptedException
  {
    final AutoResetEvent wearablesEvent = new AutoResetEvent(false);
    EventObserver<AgentWearablesReplyEventArgs> wearablesCallback =
        new EventObserver<AgentWearablesReplyEventArgs>()
        {
      @Override
      public void handleEvent(Observable s,
          AgentWearablesReplyEventArgs e)
      {
        wearablesEvent.set();                     
      }
        };

        this.registerOnAgentWearablesReply(wearablesCallback);     
        RequestAgentWearables();
        boolean success = wearablesEvent.waitOne(WEARABLE_TIMEOUT);
        this.unregisterOnAgentWearablesReply(wearablesCallback);
        return success;
  }
View Full Code Here

  /// Blocking method to populate the Textures array with cached bakes
  /// </summary>
  /// <returns>True on success, otherwise false</returns>
  boolean GetCachedBakes() throws InterruptedException
  {
    final AutoResetEvent cacheCheckEvent = new AutoResetEvent(false);
    EventObserver<AgentCachedBakesReplyEventArgs> cacheCallback =
        new EventObserver<AgentCachedBakesReplyEventArgs>()
        {
      @Override
      public void handleEvent(Observable s,
          AgentCachedBakesReplyEventArgs e) {
        cacheCheckEvent.set();                     
      }
        };

        this.registerOnCachedBakesReply(cacheCallback);

        RequestCachedBakes();

        boolean success = cacheCheckEvent.waitOne(WEARABLE_TIMEOUT);
        this.unregisterOnCachedBakesReply(cacheCallback);

        return success;
  }
View Full Code Here

      Runnable runnable = new Runnable(){
        public void run() {
          try{
            if (wearable.Asset == null)
            {
              final AutoResetEvent downloadEvent = new AutoResetEvent(false);

              MethodDelegate<Void, AssetReceivedCallbackArgs> assetReceivedCallback
              = new MethodDelegate<Void, AssetReceivedCallbackArgs>()
              {
                public Void execute(AssetReceivedCallbackArgs e) {
                  AssetDownload transfer = e.getTransfer();
                  Asset asset = e.getAsset();
                  if (transfer.Success && asset instanceof AssetWearable)
                  {
                    // Update this wearable with the freshly downloaded asset
                    wearable.Asset = (AssetWearable)asset;

                    if (wearable.Asset.Decode())
                    {
                      DecodeWearableParams(wearable);
                      JLogger.debug("Downloaded wearable asset " + wearable.WearableType + " with " + wearable.Asset.Params.size() +
                          " visual params and " + wearable.Asset.Textures.size() + " textures");

                    }
                    else
                    {
                      wearable.Asset = null;
                      JLogger.error("Failed to decode asset:" + "\n" +
                          Utils.bytesToHexDebugString(asset.AssetData, ""));
                    }
                  }
                  else
                  {
                    JLogger.warn("Wearable " + wearable.AssetID + "(" + wearable.WearableType + ") failed to download, " +
                        transfer.Status);
                  }

                  downloadEvent.set();
                  return null;
                }
              };

              // Fetch this wearable asset
              Client.assets.RequestAsset(wearable.AssetID, wearable.AssetType, true, assetReceivedCallback);


              if (!downloadEvent.waitOne(WEARABLE_TIMEOUT))
              {
                JLogger.error("Timed out downloading wearable asset " + wearable.AssetID + " (" + wearable.WearableType + ")");
                success.set(false);
              }
View Full Code Here

    for(final UUID textureID: textureIDs)
    {
      Runnable runnable = new Runnable(){
        public void run() {
          try{
            final AutoResetEvent downloadEvent = new AutoResetEvent(false);

            MethodDelegate<Void, TextureDownloadCallbackArgs> textureDownloadCallback =
                new MethodDelegate<Void, TextureDownloadCallbackArgs>()
                {
              public Void execute(TextureDownloadCallbackArgs e)
              {
                try{
                  TextureRequestState state = e.getState();
                  AssetTexture assetTexture = e.getAssetTexture();
                  if (state == TextureRequestState.Finished)
                  {
                    JLogger.info("Downloaded Texture " + textureID + " Proceeding for backing...");
                    if(assetTexture.Decode())
                    {
                      for (int i = 0; i < Textures.length; i++)
                      {
                        if (Textures[i].TextureID.equals(textureID))
                        {
                          JLogger.info("Setting AssetTextureIndex " + i + " to "+ textureID );
                          Textures[i].Texture = assetTexture;
                        }
                      }
                    }
                    else
                      throw new Exception("Failed to decode Asset texture: " + textureID );
                  }
                  else
                  {
                    JLogger.warn("Texture " + textureID + " failed to download, one or more bakes will be incomplete");
                  }

                }
                catch(Exception ex)
                {JLogger.warn("Texture " + textureID + " failed to download or parsed one or more bakes will be incomplete\n" + Utils.getExceptionStackTraceAsString(ex));}
                finally
                { downloadEvent.set();}
                return null;
              }};

              Client.assets.RequestImage(textureID, textureDownloadCallback);

              downloadEvent.waitOne(TEXTURE_TIMEOUT);
          }
          catch(Exception e)
          {
            JLogger.warn("Exception while running the task: \n" + Utils.getExceptionStackTraceAsString(e));
          }
View Full Code Here

  /// <param name="textureData">Five channel JPEG2000 texture data to upload</param>
  /// <returns>UUID of the newly created asset on success, otherwise UUID.Zero</returns>
  private UUID UploadBake(byte[] textureData) throws Exception
  {
    final UUID[] bakeID = new UUID[]{UUID.Zero};
    final AutoResetEvent uploadEvent = new AutoResetEvent(false);

    MethodDelegate<Void, BakedTextureUploadedCallbackArgs> bakedTextureUploadedCallback
    = new MethodDelegate<Void, BakedTextureUploadedCallbackArgs>()
    {
      public Void execute(
          BakedTextureUploadedCallbackArgs e) {
        UUID newAssetID = e.getNewAssetID();
        bakeID[0] = newAssetID;
        uploadEvent.set();
        return null;
      }

    };
    JLogger.debug(String.format("Going to wait %d ms for texture to get uploaded", UPLOAD_TIMEOUT));

    Client.assets.RequestUploadBakedTexture(textureData,bakedTextureUploadedCallback);


    // FIXME: evalute the need for timeout here, RequestUploadBakedTexture() will
    // timout either on Client.Settings.TRANSFER_TIMEOUT or Client.Settings.CAPS_TIMEOUT
    // depending on which upload method is used.
    uploadEvent.waitOne(UPLOAD_TIMEOUT);
    JLogger.debug("Successfully Uploaded baked Texture got asset ID: " + bakeID[0]);
    return bakeID[0];
  }
View Full Code Here

  /// handshake has completed or when <code>Settings.LOGOUT_TIMEOUT</code>
  /// has expired and the network layer is manually shut down
  /// </summary>
  public void Logout()
  {
    final AutoResetEvent logoutEvent = new AutoResetEvent(false);
    //        EventHandler<LoggedOutEventArgs> callback = delegate(Object sender, LoggedOutEventArgs e) { logoutEvent.Set(); };
    //
    //        LoggedOut += callback;

    EventObserver<LoggedOutEventArgs> callback = new EventObserver<LoggedOutEventArgs>(){
      @Override
      public void handleEvent(Observable o, LoggedOutEventArgs arg) {
        logoutEvent.set();
      }
    };

    OnLoggedOut.addObserver(callback);

    // Send the packet requesting a clean logout
    RequestLogout();

    // Wait for a logout response. If the response is received, shutdown
    // will be fired in the callback. Otherwise we fire it manually with
    // a NetworkTimeout type
    try {
      if (!logoutEvent.waitOne(client.settings.LOGOUT_TIMEOUT))
        Shutdown(DisconnectType.NetworkTimeout);
    } catch (InterruptedException e) {
      JLogger.warn("Thread got interruped while waiting for logout event");
      Shutdown(DisconnectType.NetworkTimeout);
    }
View Full Code Here

        {
          gesture[0] = gestureCache.get(gestureID);
        }
        else
        {
          final AutoResetEvent gotAsset = new AutoResetEvent(false);

          MethodDelegate<Void, AssetReceivedCallbackArgs> assetReceivedCallback = new MethodDelegate<Void, AssetReceivedCallbackArgs>()
              {
            public Void execute(
                AssetReceivedCallbackArgs e) {
              if (e.getTransfer().Success)
              {
                gesture[0] = (AssetGesture)e.getAsset();
              }

              gotAsset.set();
              return null;
            }

              };
              Client.assets.RequestAsset(gestureID, AssetType.Gesture, true,
                  assetReceivedCallback);

              try {
                gotAsset.waitOne(30 * 1000);
              } catch (InterruptedException e1) {
                JLogger.error("Error while playing a gesture: " + Utils.getExceptionStackTraceAsString(e1));
              }

              if (gesture[0] != null && gesture[0].Decode())
View Full Code Here

    if (Client.network.getCurrentSim() == null ||
        Client.network.getCurrentSim().Caps == null ||
        !Client.network.getCurrentSim().Caps.isEventQueueRunning())
    {
      // Wait a bit to see if the event queue comes online
      final AutoResetEvent queueEvent = new AutoResetEvent(false);
      //                    EventHandler<EventQueueRunningEventArgs> queueCallback =
      //                        delegate(Object sender, EventQueueRunningEventArgs e)
      //                        {
      //                            if (e.getSimulator() == Client.network.getCurrentSim())
      //                                queueEvent.Set();
      //                        };
      //   
      //                    Client.network.EventQueueRunning += queueCallback;
      //                    queueEvent.WaitOne(10 * 1000, false);
      //                    Client.network.EventQueueRunning -= queueCallback;

      EventObserver<EventQueueRunningEventArgs> queueCallback = new EventObserver<EventQueueRunningEventArgs>()
          { @Override
        public void handleEvent(Observable o, EventQueueRunningEventArgs e)
          {
            if (e.getSimulator().equals(Client.network.getCurrentSim()))
              queueEvent.set();
          }
          };
          Client.network.RegisterOnEventQueueRunningCallback(queueCallback);
          queueEvent.waitOne(10 * 1000);
          Client.network.UnregisterOnEventQueueRunningCallback(queueCallback);                   
    }

    teleportStat = TeleportStatus.None;
    teleportEvent.reset();
View Full Code Here

TOP

Related Classes of com.ngt.jopenmetaverse.shared.sim.events.AutoResetEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.