public static class FinagledClient extends {{parent}} implements FutureIface {
  private com.twitter.finagle.Service<ThriftClientRequest, byte[]> service;
  private TProtocolFactory protocolFactory /* new TBinaryProtocol.Factory */;
  private StatsReceiver scopedStats;

  public FinagledClient(
      com.twitter.finagle.Service<ThriftClientRequest, byte[]> service,
      TProtocolFactory protocolFactory /* new TBinaryProtocol.Factory */,
      String serviceName,
      StatsReceiver stats) {

{{#hasParent}}
    super(service, protocolFactory, serviceName, stats);
{{/hasParent}}
{{^hasParent}}
    super(service, protocolFactory, serviceName);
{{/hasParent}}
    this.service = service;
    this.protocolFactory = protocolFactory;
    if (serviceName != "") {
      this.scopedStats = stats.scope(serviceName);
    } else {
      this.scopedStats = stats;
    }
  }

{{#functions}}
  {{>function}}
{{/function}}
}

@@ -31,20 +31,48 @@
 ient
- extends %7B%7Bp
+%7B%7B#hasParent%7D%7D extends %7B%7Bparent%7D%7D%7B%7B/hasP
 aren
@@ -321,18 +321,16 @@
 nt(%0A    
-  
 com.twit
@@ -387,18 +387,16 @@
 ervice,%0A
-  
     TPro
@@ -459,18 +459,16 @@
 ory */,%0A
-  
     Stri
@@ -487,18 +487,16 @@
 me,%0A    
-  
 StatsRec
@@ -510,13 +510,15 @@
 tats
+%0A  
 ) %7B%0A
-%0A
 %7B%7B#h
@@ -604,140 +604,448 @@
 t%7D%7D%0A
-%7B%7B%5EhasParent%7D%7D%0A    super(service, protocolFactory, serviceName);%0A%7B%7B/hasParent%7D%7D%0A    this.service = service;%0A    this.protocolFactory
+    this.service = service;%0A    this.protocolFactory = protocolFactory;%0A    if (serviceName != %22%22) %7B%0A      this.scopedStats = stats.scope(serviceName);%0A    %7D else %7B%0A      this.scopedStats = stats;%0A    %7D%0A  %7D%0A%0A%7B%7B%5EhasParent%7D%7D%0A  // ----- boilerplate that should eventually be moved into finagle:%0A%0A  protected ThriftClientRequest encodeRequest(String name, ThriftStruct args) %7B%0A    TMemoryBuffer buf = new TMemoryBuffer(512);%0A    TProtocol oprot
  = p
@@ -1062,146 +1062,1162 @@
 tory
+.getProtocol(buf)
 ;%0A
+%0A
     
-if (serviceName != %22%22) %7B%0A      this.scopedStats = stats.scope(serviceName);%0A    %7D else %7B%0A      this.scopedStats = stats;
+oprot.writeMessageBegin(new TMessage(name, TMessageType.CALL, 0));%0A    args.write(oprot);%0A    oprot.writeMessageEnd();%0A%0A    byte%5B%5D bytes = Arrays.copyOfRange(buf.getArray(), 0, buf.length);%0A    return new ThriftClientRequest(bytes, false);%0A  %7D%0A%0A  protected T decodeResponse%3CT extends ThriftStruct%3E(byte%5B%5D resBytes, ThriftStructCodec%3CT%3E codec) %7B%0A    TProtocol iprot = protocolFactory.getProtocol(new TMemoryInputTransport(resBytes));%0A    TMessage msg = iprot.readMessageBegin();%0A    try %7B%0A      if (msg.type == TMessageType.EXCEPTION) %7B%0A        Exception exception = TApplicationException.read(iprot);%0A        if (exception instanceof SourcedException) %7B%0A          if (serviceName != %22%22) ((SourcedException) exception).serviceName = serviceName;%0A        %7D%0A        throw exception;%0A      %7D else %7B%0A        return codec.decode(iprot);%0A      %7D%0A    %7D finally %7B%0A      iprot.readMessageEnd();%0A    %7D%0A  %7D%0A%0A  protected Exception missingResult(String name) %7B%0A    return new TApplicationException(%0A      TApplicationException.MISSING_RESULT,%0A      %22%60%22 + name + %22%60 failed: unknown result%22
 %0A    
-%7D
+)
 %0A  %7D%0A%0A
+  // ----- end boilerplate.%0A%0A%7B%7B/hasParent%7D%7D%0A
 %7B%7B#f

fix up java code (probably -- i don't think this is tested yet).