/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.nanos.boot;

import foam.core.*;
import foam.nanos.*;

public class NSpecFactory
  implements XFactory
{
  NSpec  spec_;
  ProxyX x_;

  public NSpecFactory(ProxyX x, NSpec spec) {
    x_    = x;
    spec_ = spec;
  }

  public Object create(X x) {
    Object ns = null;

    try {
      ns = spec_.createService(x_.getX());

      if ( ns instanceof ContextAware ) ((ContextAware) ns).setX(x_.getX());
      if ( ns instanceof NanoService  ) ((NanoService)  ns).start();
    } catch (Throwable t) {
      // TODO: LOG
      t.printStackTrace();
    }

    return ns;
  }
}

@@ -183,16 +183,41 @@
 nanos.*;
+%0Aimport foam.nanos.pm.PM;
 %0A%0Apublic
@@ -269,16 +269,17 @@
  NSpec  
+ 
 spec_;%0A 
@@ -290,11 +290,43 @@
 xyX 
+ 
 x_;
+%0A  boolean isCreating_ = false;
 %0A%0A  
@@ -445,24 +445,236 @@
     
-Object ns = null
+// Avoid infinite recursions when creating services%0A    if ( isCreating_ ) %7B%0A      return null;%0A    %7D%0A%0A    isCreating_ = true;%0A%0A    Object ns = null;%0A    PM     pm = new PM(this.getClass(), spec_ == null ? %22-%22 : spec_.getName())
 ;%0A%0A 
@@ -947,24 +947,92 @@
 ace();%0A    %7D
+ finally %7B%0A      pm.log(x_.getX());%0A      isCreating_ = false;%0A    %7D
 %0A%0A    return

Add PMs to service creation.