Beispiel #1
0
 /// <exception cref="System.IO.IOException"/>
 public override void RemoveSpanReceiver(long spanReceiverId)
 {
     lock (this)
     {
         SpanReceiver rcvr = Collections.Remove(receivers, spanReceiverId);
         if (rcvr == null)
         {
             throw new IOException("There is no span receiver with id " + spanReceiverId);
         }
         Trace.RemoveReceiver(rcvr);
         rcvr.Close();
         Log.Info("Successfully removed SpanReceiver " + spanReceiverId + " with class " +
                  rcvr.GetType().FullName);
     }
 }
Beispiel #2
0
 /// <exception cref="System.IO.IOException"/>
 private SpanReceiver LoadInstance(string className, IList <SpanReceiverInfo.ConfigurationPair
                                                            > extraConfig)
 {
     lock (this)
     {
         SpanReceiverBuilder builder = new SpanReceiverBuilder(TraceUtils.WrapHadoopConf(confPrefix
                                                                                         , config, extraConfig));
         SpanReceiver rcvr = builder.SpanReceiverClass(className.Trim()).Build();
         if (rcvr == null)
         {
             throw new IOException("Failed to load SpanReceiver " + className);
         }
         return(rcvr);
     }
 }
Beispiel #3
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);
             }
         }
     }
 }
Beispiel #4
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);
     }
 }