Package com.ngt.jopenmetaverse.shared.structureddata

Examples of com.ngt.jopenmetaverse.shared.structureddata.OSDMap


  public void Start() throws Exception
  {
    _Dead = false;

    // Create an EventQueueGet request
    OSDMap request = new OSDMap();
    request.put("ack", new OSD());
    request.put("done", OSD.FromBoolean(false));

    byte[] postData = XmlLLSDOSDParser.SerializeLLSDXmlBytes(request);

    _Request = HttpBaseClient.UploadDataAsync(_Address, null, "application/xml", postData, REQUEST_TIMEOUT
        , internalOpenWriteObservable, null, internalRequestCompletedObservable);
View Full Code Here


    if (responseData != null)
    {
      _errorCount = 0;
      // Got a response
      OSDMap result = (OSDMap)XmlLLSDOSDParser.DeserializeLLSDXml(responseData);

      if (result != null)
      {
        events = (OSDArray)result.get("events");
        ack = result.get("id").asInteger();
      }
      else
      {
       
        try {
          logger.warning("Got an unparseable response from the event queue: \"" +
              Utils.bytesToString(responseData) + "\"");
        } catch (UnsupportedEncodingException e) {
          logger.warning("Got an unparseable response from the event queue: \"" +
              Utils.getExceptionStackTraceAsString(e) + "\"");
        }
      }
    }
    else if (error != null)
    {
      //TODO Handle the case when the request is aborted or there is some client side error

      if(response !=null)
      {
      //region Error handling
      int code = response.getStatusLine().getStatusCode();

      if(code == HttpStatus.SC_GONE || code == HttpStatus.SC_NOT_FOUND)
      {
        logger.info(String.format("Closing event queue at {0} due to missing caps URI", _Address));
        _Running = false;
        _Dead = true;       
      }
      else if(code == HttpStatus.SC_BAD_GATEWAY)
      {
        // This is not good (server) protocol design, but it's normal.
        // The EventQueue server is a proxy that connects to a Squid
        // cache which will time out periodically. The EventQueue server
        // interprets this as a generic error and returns a 502 to us
        // that we ignore
      }
      else
      {
        ++_errorCount;       
        // Try to log a meaningful error message
        if (code != HttpStatus.SC_OK)
        {
          logger.warning(String.format("Unrecognized caps connection problem from %s: %s",
              _Address, code));
        }
        else
        {
          logger.warning(String.format("Unrecognized caps exception from %s: %s",
              _Address, error.getMessage()));
        }       
      }
      }
      else
      {
        ++_errorCount;
        logger.warning("Some client Side Error" + Utils.getExceptionStackTraceAsString(error));
      }
    }
    else
    {
      ++_errorCount;
      logger.warning("No response from the event queue but no reported error either");
   

    //      if (error instanceof HttpException)
    //      {
    //        HttpException webException = (HttpException)error;
    //
    //        if (response != null)
    //          code = response.getStatusLine().getStatusCode();
    //        else if (webException.Status == WebExceptionStatus.RequestCanceled)
    //          goto HandlingDone;
    //      }
    //
    //      if (error is WebException && ((WebException)error).Response != null)
    //        code = ((HttpWebResponse)((WebException)error).Response).StatusCode;
    //
    //      if (code == HttpStatusCode.NotFound || code == HttpStatusCode.Gone)
    //      {
    //        Logger.Log(String.format("Closing event queue at {0} due to missing caps URI", _Address), Helpers.LogLevel.Info);
    //
    //        _Running = false;
    //        _Dead = true;
    //      }
    //      else if (code == HttpStatusCode.BadGateway)
    //      {
    //        // This is not good (server) protocol design, but it's normal.
    //        // The EventQueue server is a proxy that connects to a Squid
    //        // cache which will time out periodically. The EventQueue server
    //        // interprets this as a generic error and returns a 502 to us
    //        // that we ignore
    //      }
    //      else
    //      {
    //        ++_errorCount;
    //
    //        // Try to log a meaningful error message
    //        if (code != HttpStatusCode.OK)
    //        {
    //          Logger.Log(String.format("Unrecognized caps connection problem from {0}: {1}",
    //              _Address, code), Helpers.LogLevel.Warning);
    //        }
    //        else if (error.InnerException != null)
    //        {
    //          Logger.Log(String.Format("Unrecognized internal caps exception from {0}: {1}",
    //              _Address, error.InnerException.Message), Helpers.LogLevel.Warning);
    //        }
    //        else
    //        {
    //          Logger.Log(String.Format("Unrecognized caps exception from {0}: {1}",
    //              _Address, error.Message), Helpers.LogLevel.Warning);
    //        }
    //      }
    //
    //      //endregion Error handling
    //    }
    //    else
    //    {
    //      ++_errorCount;
    //
    //      Logger.Log("No response from the event queue but no reported error either", Helpers.LogLevel.Warning);
    //    }
    //
    //    HandlingDone:
    //
    //      //region Resume the connection
    //
    //      if (_Running)
    //      {
    //        OSDMap osdRequest = new OSDMap();
    //        if (ack != 0) osdRequest["ack"] = OSD.FromInteger(ack);
    //        else osdRequest["ack"] = new OSD();
    //        osdRequest["done"] = OSD.FromBoolean(_Dead);
    //
    //        byte[] postData = OSDParser.SerializeLLSDXmlBytes(osdRequest);
    //
    //        if (_errorCount > 0) // Exponentially back off, so we don't hammer the CPU
    //          Thread.Sleep(_random.Next(500 + (int)Math.Pow(2, _errorCount)));
    //
    //        // Resume the connection. The event handler for the connection opening
    //        // just sets class _Request variable to the current HttpRequest
    //        CapsBase.UploadDataAsync(_Address, null, "application/xml", postData, REQUEST_TIMEOUT,
    //            delegate(HttpRequest newRequest) { _Request = newRequest; }, null, RequestCompletedHandler);
    //
    //        // If the event queue is dead at this point, turn it off since
    //        // that was the last thing we want to do
    //        if (_Dead)
    //        {
    //          _Running = false;
    //          Logger.DebugLog("Sent event queue shutdown message");
    //        }
    //      }
    //
    //    //endregion Resume the connection
    //
    //    //region Handle incoming events
    //
    //    if (OnEvent != null && events != null && events.Count > 0)
    //    {
    //      // Fire callbacks for each event received
    //      foreach (OSDMap evt in events)
    //      {
    //        string msg = evt["message"].AsString();
    //        OSDMap body = (OSDMap)evt["body"];
    //
    //        try { OnEvent(msg, body); }
    //        catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, ex); }
    //      }
    //    }
    //
    ////    endregion Handle incoming events
   
   
     //region Handle incoming events
         if (eventObservable != null && events != null && events.count() > 0)
         {
             //Fire callbacks for each event received
           Iterator<OSD> itr = events.iterator();
             while(itr.hasNext())
             {
               OSDMap evt = (OSDMap)itr.next();
                 String msg = evt.get("message").asString();
                 OSDMap body = (OSDMap)evt.get("body");

                 try
                 {
                   eventObservable.raiseEvent(new EventQueueClientEventObservableArg(msg, body));
                 }
View Full Code Here

     
      doc.endArray();
     
      break;
    case Map:
      OSDMap map = (OSDMap)data;

      doc.beginObject();
      for(Map.Entry<String, OSD> entry: map.entrySet())
      {
        JsonWriter tempWriter = doc.name(entry.getKey());
       
        SerializeLLSDJsonElement(tempWriter, entry.getValue());       
      }     
View Full Code Here

  private static OSDMap ParseLLSDJsonMap(JsonObject jobject) throws OSDException, URISyntaxException
  {

    //System.out.println("Parsing Map...");

    OSDMap map = new OSDMap();
    for(Entry<String, JsonElement> entry :jobject.entrySet())
    {
      //System.out.println("Parsing Map Key..." + entry.getKey());
      map.put(entry.getKey(), ParseLLSDJsonElement(entry.getValue()));
    }

    return map;
  }
View Full Code Here

         }

         private static OSD DeserializeLLSDNotationMap(StringReader reader) throws IOException, OSDException
         {
             int character;
             OSDMap osdMap = new OSDMap();
             while (((character = PeekAndSkipWhitespace(reader)) > 0) &&
                   ((char)character != mapEndNotationMarker))
             {
                 OSD osdKey = DeserializeLLSDNotationElement(reader);
                 if (osdKey.getType() != OSDType.String)
                     throw new OSDException("Notation LLSD parsing: Invalid key in map");
                 String key = osdKey.asString();

                 character = ReadAndSkipWhitespace(reader);
                 if ((char)character != keyNotationDelimiter)
                     throw new OSDException("Notation LLSD parsing: Unexpected end of stream in map.");
                 if ((char)character != keyNotationDelimiter)
                     throw new OSDException("Notation LLSD parsing: Invalid delimiter in map.");

                 osdMap.put(key, DeserializeLLSDNotationElement(reader));
                 character = ReadAndSkipWhitespace(reader);
                 if (character < 0)
                     throw new OSDException("Notation LLSD parsing: Unexpected end of map discovered.");
                 else if ((char)character == kommaNotationDelimiter)
                     continue;
View Full Code Here

    /// </summary>
    /// <param name="map">An <see cref="OSDMap"/> containing the data</param>
    public void Deserialize(OSDMap map)
    {

      OSDMap agent_updates = (OSDMap)map.get("agent_updates");
      SessionID = map.get("session_id").asUUID();

      List<AgentUpdatesBlock> updatesList = new ArrayList<AgentUpdatesBlock>();

      for(Entry<String, OSD> kvp :agent_updates.entrySet())
      {

        if (kvp.getKey().equals("updates"))
        {
          // This appears to be redundant and duplicated by the info block, more dumps will confirm this
          /* <key>32939971-a520-4b52-8ca5-6085d0e39933</key>
                            <string>ENTER</string> */
        }
        else if (kvp.getKey().equals("session_id"))
        {
          // I am making the assumption that each osdmap will contain the information for a
          // single session. This is how the map appears to read however more dumps should be taken
          // to confirm this.
          /* <key>session_id</key>
                            <string>984f6a1e-4ceb-6366-8d5e-a18c6819c6f7</string> */

        }
        else  // key is an agent uuid (we hope!)
        {
          // should be the agents uuid as the key, and "info" as the datablock
          /* <key>32939971-a520-4b52-8ca5-6085d0e39933</key>
                            <map>
                                <key>info</key>
                                    <map>
                                        <key>can_voice_chat</key>
                                            <boolean>1</boolean>
                                        <key>is_moderator</key>
                                            <boolean>1</boolean>
                                    </map>
                                <key>transition</key>
                                    <string>ENTER</string>
                            </map>*/
          AgentUpdatesBlock block = new AgentUpdatesBlock();
          block.AgentID = UUID.Parse(kvp.getKey());

          OSDMap infoMap = (OSDMap)kvp.getValue();

          OSDMap agentPermsMap = (OSDMap)infoMap.get("info");

          block.CanVoiceChat = agentPermsMap.get("can_voice_chat").asBoolean();
          block.IsModerator = agentPermsMap.get("is_moderator").asBoolean();

          block.Transition = infoMap.get("transition").asString();

          if (agentPermsMap.containsKey("mutes"))
          {
            OSDMap mutesMap = (OSDMap)agentPermsMap.get("mutes");
            block.MuteText = mutesMap.get("text").asBoolean();
            block.MuteVoice = mutesMap.get("voice").asBoolean();
          }
          updatesList.add(block);
        }
      }

View Full Code Here

    /// Serialize the object
    /// </summary>
    /// <returns>An <see cref="OSDMap"/> containing the objects data</returns>
    public OSDMap Serialize()
    {
      OSDMap map = new OSDMap(2);
      map.put("reason", OSD.FromString(Reason));
      map.put("session_id", OSD.FromUUID(SessionID));

      return map;
    }
View Full Code Here

    /// <returns>An <see cref="OSDMap"/> containing the objects data</returns>

    @Override
    public OSDMap Serialize()
    {
      OSDMap map = new OSDMap();
      map.put("ack", OSD.FromInteger(AckID));
      map.put("done", OSD.FromBoolean(Done));
      return map;
    }
View Full Code Here

    /// <returns>An <see cref="OSDMap"/> containing the objects data</returns>

    @Override
    public OSDMap Serialize()
    {
      OSDMap map = new OSDMap(1);

      OSDArray eventsArray = new OSDArray();

      for (int i = 0; i < MessageEvents.length; i++)
      {
        OSDMap eventMap = new OSDMap(2);
        eventMap.put("body", MessageEvents[i].EventMessage.Serialize());
        eventMap.put("message", OSD.FromString(MessageEvents[i].MessageKey));
        eventsArray.add(eventMap);
      }

      map.put("events", eventsArray);
      map.put("id", OSD.FromInteger(Sequence));
View Full Code Here

      MessageEvents = new QueueEvent[arrayEvents.count()];

      for (int i = 0; i < arrayEvents.count(); i++)
      {
        OSDMap eventMap = (OSDMap)arrayEvents.get(i);
        QueueEvent ev = new QueueEvent();

        ev.MessageKey = eventMap.get("message").asString();
        ev.EventMessage = MessageUtils.DecodeEvent(ev.MessageKey, (OSDMap)eventMap.get("body"));
        MessageEvents[i] = ev;
      }
    }
View Full Code Here

TOP

Related Classes of com.ngt.jopenmetaverse.shared.structureddata.OSDMap

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.