Exemple #1
0
 /// <summary>
 /// Reads the names of classes specified in the
 /// "hadoop.htrace.spanreceiver.classes" property and instantiates and registers
 /// them with the Tracer as SpanReceiver's.
 /// </summary>
 /// <remarks>
 /// Reads the names of classes specified in the
 /// "hadoop.htrace.spanreceiver.classes" property and instantiates and registers
 /// them with the Tracer as SpanReceiver's.
 /// The nullary constructor is called during construction, but if the classes
 /// specified implement the Configurable interface, setConfiguration() will be
 /// called on them. This allows SpanReceivers to use values from the Hadoop
 /// configuration.
 /// </remarks>
 public virtual void LoadSpanReceivers(Configuration conf)
 {
     lock (this)
     {
         config = new Configuration(conf);
         string   receiverKey   = confPrefix + SpanReceiversConfSuffix;
         string[] receiverNames = config.GetTrimmedStrings(receiverKey);
         if (receiverNames == null || receiverNames.Length == 0)
         {
             if (Log.IsTraceEnabled())
             {
                 Log.Trace("No span receiver names found in " + receiverKey + ".");
             }
             return;
         }
         // It's convenient to have each daemon log to a random trace file when
         // testing.
         string pathKey = confPrefix + LocalFileSpanReceiverPathSuffix;
         if (config.Get(pathKey) == null)
         {
             string uniqueFile = GetUniqueLocalTraceFileName();
             config.Set(pathKey, uniqueFile);
             if (Log.IsTraceEnabled())
             {
                 Log.Trace("Set " + pathKey + " to " + uniqueFile);
             }
         }
         foreach (string className in receiverNames)
         {
             try
             {
                 SpanReceiver rcvr = LoadInstance(className, Empty);
                 Trace.AddReceiver(rcvr);
                 receivers[highestId++] = rcvr;
                 Log.Info("Loaded SpanReceiver " + className + " successfully.");
             }
             catch (IOException e)
             {
                 Log.Error("Failed to load SpanReceiver", e);
             }
         }
     }
 }
Exemple #2
0
 /// <exception cref="System.IO.IOException"/>
 public override long AddSpanReceiver(SpanReceiverInfo info)
 {
     lock (this)
     {
         StringBuilder configStringBuilder = new StringBuilder();
         string        prefix = string.Empty;
         foreach (SpanReceiverInfo.ConfigurationPair pair in info.configPairs)
         {
             configStringBuilder.Append(prefix).Append(pair.GetKey()).Append(" = ").Append(pair
                                                                                           .GetValue());
             prefix = ", ";
         }
         SpanReceiver rcvr = null;
         try
         {
             rcvr = LoadInstance(info.GetClassName(), info.configPairs);
         }
         catch (IOException e)
         {
             Log.Info("Failed to add SpanReceiver " + info.GetClassName() + " with configuration "
                      + configStringBuilder.ToString(), e);
             throw;
         }
         catch (RuntimeException e)
         {
             Log.Info("Failed to add SpanReceiver " + info.GetClassName() + " with configuration "
                      + configStringBuilder.ToString(), e);
             throw;
         }
         Trace.AddReceiver(rcvr);
         long newId = highestId++;
         receivers[newId] = rcvr;
         Log.Info("Successfully added SpanReceiver " + info.GetClassName() + " with configuration "
                  + configStringBuilder.ToString());
         return(newId);
     }
 }