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

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


        threadPool.execute(new Runnable(){
          public void run()
          {
            try
            {
            final AutoResetEvent gotMuteList = new AutoResetEvent(false);
            String fileName = Utils.bytesWithTrailingNullByteToString(packet.MuteData.Filename);
            String muteList = "";
            final BigInteger[] xferID = new BigInteger[]{new BigInteger("0")};
            final byte[][] assetData = new byte[1][];
   
            EventObserver<XferReceivedEventArgs> xferCallback = new EventObserver<XferReceivedEventArgs>()
                {
                  @Override
                  public void handleEvent(Observable sender,
                      XferReceivedEventArgs xe) {
                    if (xe.getXfer().XferID.equals(xferID[0]))
                      {
                        assetData[0] = xe.getXfer().AssetData;
                        gotMuteList.set();
                      }
                  } 
                };
           
          Client.assets.registerOnXferReceived(xferCallback);
           
          xferID[0] = Client.assets.RequestAssetXfer(fileName, true, false, UUID.Zero, AssetType.Unknown, true);
   
            if (gotMuteList.waitOne(60 * 1000))
            {
              muteList = Utils.bytesWithTrailingNullByteToString(assetData[0]);
   
              synchronized (MuteList.getDictionary())
              {
View Full Code Here


  /// <param name="timeoutMS"></param>
  /// <returns></returns>
  public List<MapItem> MapItems(BigInteger regionHandle, GridItemType item, GridLayerType layer, int timeoutMS) throws InterruptedException
  {
    List<MapItem> itemList = null;
    final AutoResetEvent itemsEvent = new AutoResetEvent(false);

    //            EventHandler<GridItemsEventArgs> callback =
    //                delegate(Object sender, GridItemsEventArgs e)
    //                {
    //                    if (e.Type == GridItemType.AgentLocations)
    //                    {
    //                        itemList = e.Items;
    //                        itemsEvent.Set();
    //                    }
    //                };
    //
    //            GridItems += callback;
    //
    //            RequestMapItems(regionHandle, item, layer);

    final Object[] itemListArray = new Object[]{null}
    EventObserver<GridItemsEventArgs> callback = new EventObserver<GridItemsEventArgs>()
        {
      @Override
      public void handleEvent(Observable o, GridItemsEventArgs e) {
        if (e.getType().equals(GridItemType.AgentLocations))
        {
          itemListArray[0] = e.getItems();
          itemsEvent.set();
        }} 
        };
        itemList = (List<MapItem>)itemListArray[0];

        OnGridItems.addObserver(callback);
        RequestMapItems(regionHandle, item, layer);

        itemsEvent.waitOne(timeoutMS);

        OnGridItems.deleteObserver(callback);

        return itemList;
  }
View Full Code Here

      region[0] = Regions.get(name);
      return true;
    }
    else
    {
      final AutoResetEvent regionEvent = new AutoResetEvent(false);

      EventObserver<GridRegionEventArgs> callback = new EventObserver<GridRegionEventArgs>()
          { @Override
        public void handleEvent(Observable o, GridRegionEventArgs e)
          {
            if (e.getRegion().Name.equals(name))
              regionEvent.set();
          }
          };

          OnGridRegion.addObserver(callback);

          RequestMapRegion(name, layer);
          regionEvent.waitOne(Client.settings.MAP_REQUEST_TIMEOUT);

          OnGridRegion.deleteObserver(callback);

          if (Regions.containsKey(name))
          {
View Full Code Here

        synchronized(PendingUploadLock)
        {
            final int UPLOAD_CONFIRM_TIMEOUT = 20 * 1000;
            final int SLEEP_INTERVAL = 50;
            int t = 0;
            AutoResetEvent sleepEvent = new AutoResetEvent(false);
            while (WaitingForUploadConfirm && t < UPLOAD_CONFIRM_TIMEOUT)
            {
//                System.Threading.Thread.Sleep(SLEEP_INTERVAL);
                sleepEvent.waitOne(SLEEP_INTERVAL);
                t += SLEEP_INTERVAL;
            }

            if (t < UPLOAD_CONFIRM_TIMEOUT)
            {
View Full Code Here

         
          threadPool.execute(new Runnable(){
        public void run()
        {
                  final UUID transactionID = UUID.Random();
                  final AutoResetEvent uploadEvent = new AutoResetEvent(false);
                  EventObserver<AssetUploadEventArgs> udpCallback = new EventObserver<AssetUploadEventArgs>()
                      {
              @Override
              public void handleEvent(Observable sender,
                  AssetUploadEventArgs e) {
                if (e.getUpload().ID.equals(transactionID))
                              {
                                  uploadEvent.set();
                                  uploadCallback.execute(new BakedTextureUploadedCallbackArgs(e.getUpload().Success ? e.getUpload().AssetID : UUID.Zero));
                              }
              }
                      };
                

                  onAssetUploaded.addObserver(udpCallback);

                  boolean success;
                  try
                  {
                    UploadRequestResult uploadResult = RequestUpload(AssetType.Texture, textureData, true, transactionID);
                      success = uploadEvent.waitOne(Client.settings.TRANSFER_TIMEOUT);
                  }
                  catch (Exception e)
                  {
                    JLogger.warn(e);
                      success = false;
View Full Code Here

    _Running = false;
   
    // Pre-configure autoreset events and threadpool slots
    for (int i = 0; i < maxTextureRequests; i++)
    {
      resetEvents[i] = new AutoResetEvent(true);
      threadpoolSlots[i] = -1;
    }

    // Handle client connected and disconnected events
    client.network.RegisterLoginProgressCallback(new EventObserver<LoginProgressEventArgs>()
View Full Code Here

  /// <param name="timeoutMS">a integer representing the number of milliseconds to wait for results</param>
  /// <returns>An <seealso cref="InventoryItem"/> object on success, or null if no item was found</returns>
  /// <remarks>Items will also be sent to the <seealso cref="InventoryManager.OnItemReceived"/> event</remarks>
  public InventoryItem FetchItem(final UUID itemID, UUID ownerID, int timeoutMS) throws InterruptedException
  {
    final AutoResetEvent fetchEvent = new AutoResetEvent(false);
    InventoryItem fetchedItem = null;

    final InventoryItem[] fetchedItemArray = new InventoryItem[]{null};
    EventObserver<ItemReceivedEventArgs> callback =
        new EventObserver<ItemReceivedEventArgs>()
        {

      @Override
      public void handleEvent(Observable o, ItemReceivedEventArgs e) {
        if (e.getItem().UUID.equals(itemID))
        {
          fetchedItemArray[0] = e.getItem();
          fetchEvent.set();
        }
      }           
        };
        fetchedItem = fetchedItemArray[0];

        onItemReceived.addObserver(callback);
        RequestFetchInventory(itemID, ownerID);

        fetchEvent.waitOne(timeoutMS);
        onItemReceived.deleteObserver(callback);

        return fetchedItem;
  }
View Full Code Here

  /// requested</remarks>
  public List<InventoryBase> FolderContents(final UUID folder, UUID owner, boolean folders, boolean items,
      InventorySortOrder order, int timeoutMS) throws InterruptedException, InventoryException
      {
    List<InventoryBase> objects = null;
    final AutoResetEvent fetchEvent = new AutoResetEvent(false);

    EventObserver<FolderUpdatedEventArgs> callback = new EventObserver<FolderUpdatedEventArgs>() { 
      @Override
      public void handleEvent(Observable o, FolderUpdatedEventArgs e)
      {
        if (e.getFolderID().equals(folder)   && _Store.get(folder) instanceof InventoryFolder)
        {
          try{
            // InventoryDescendentsHandler only stores DescendendCount if both folders and items are fetched.
            if (_Store.GetContents(folder).size() >= ((InventoryFolder)_Store.get(folder)).DescendentCount)
            {
              fetchEvent.set();
            }
          }
          catch(InventoryException ex)
          { JLogger.error("Error in Inventory " + Utils.getExceptionStackTraceAsString(ex));}
        }
        else
        {
          fetchEvent.set();
        }
      }};

      onFolderUpdated.addObserver(callback);

      RequestFolderContents(folder, owner, folders, items, order);
      if (fetchEvent.waitOne(timeoutMS))
        objects = _Store.GetContents(folder);

      onFolderUpdated.deleteObserver(callback);

      return objects;
View Full Code Here

  /// <param name="timeoutMS">milliseconds to wait for a reply</param>
  /// <returns>Found items <seealso cref="UUID"/> or <seealso cref="UUID.Zero"/> if
  /// timeout occurs or item is not found</returns>
  public UUID FindObjectByPath(UUID baseFolder, UUID inventoryOwner, final String path, int timeoutMS) throws InterruptedException
  {
    final AutoResetEvent findEvent = new AutoResetEvent(false);
    final UUID[] foundItem = new UUID[] {UUID.Zero};

    EventObserver<FindObjectByPathReplyEventArgs> callback = new EventObserver<FindObjectByPathReplyEventArgs>()
        {

      @Override
      public void handleEvent(Observable o,
          FindObjectByPathReplyEventArgs e) {
        if (e.getPath().equals(path))
        {
          foundItem[0] = e.getInventoryObjectID();
          findEvent.set();
        }
      }};
      onFindObjectByPathReply.addObserver(callback);

      RequestFindObjectByPath(baseFolder, inventoryOwner, path);
      findEvent.waitOne(timeoutMS);

      onFindObjectByPathReply.deleteObserver(callback);

      return foundItem[0];
View Full Code Here

  /// <remarks>This request blocks until the response from the simulator arrives
  /// or timeoutMS is exceeded</remarks>
  public List<InventoryBase> GetTaskInventory(final UUID objectID, long objectLocalID, int timeoutMS) throws InterruptedException, UnsupportedEncodingException
  {
    final String[] filename = new String[]{null};
    final AutoResetEvent taskReplyEvent = new AutoResetEvent(false);

    EventObserver<TaskInventoryReplyEventArgs> callback = new EventObserver<TaskInventoryReplyEventArgs>()
        //          delegate(Object sender, TaskInventoryReplyEventArgs e)
        {
      @Override
      public void handleEvent(Observable o,
          TaskInventoryReplyEventArgs e) {
        if (e.getItemID().equals(objectID))
        {
          filename[0] = e.getAssetFilename();
          taskReplyEvent.set();
        }             
      }

        };

        onTaskInventoryReply.addObserver(callback);

        RequestTaskInventory(objectLocalID);

        if (taskReplyEvent.waitOne(timeoutMS))
        {
          onTaskInventoryReply.deleteObserver(callback);

          if (!Utils.isNullOrEmpty(filename[0]))
          {
            final byte[][] assetData = new byte[][]{null};
            final BigInteger[] xferID = new BigInteger[]{new BigInteger("0")};
            final AutoResetEvent taskDownloadEvent = new AutoResetEvent(false);

            EventObserver<XferReceivedEventArgs> xferCallback = new EventObserver<XferReceivedEventArgs>()
                //                  delegate(Object sender, XferReceivedEventArgs e)
                {
              @Override
              public void handleEvent(Observable o,
                  XferReceivedEventArgs e) {
                if (e.getXfer().XferID.equals(xferID[0]))
                {
                  assetData[0] = e.getXfer().AssetData;
                  taskDownloadEvent.set();
                }}
                };
                Client.assets.registerOnXferReceived(xferCallback);

                // Start the actual asset xfer
                xferID[0] = Client.assets.RequestAssetXfer(filename[0], true, false, UUID.Zero, AssetType.Unknown, true);

                if (taskDownloadEvent.waitOne(timeoutMS))
                {
                  Client.assets.unregisterOnXferReceived(xferCallback);

                  String taskList = Utils.bytesWithTrailingNullByteToString(assetData[0]);
                  return ParseTaskInventory(taskList);
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.