/**
 * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.language.connector.debug;

import org.fudgemsg.FudgeContext;
import org.fudgemsg.FudgeMsg;
import org.fudgemsg.ImmutableFudgeMsg;

import com.opengamma.language.connector.Client;
import com.opengamma.language.connector.ClientContext;
import com.opengamma.language.connector.UserMessagePayload;
import com.opengamma.language.context.MutableSessionContext;
import com.opengamma.language.context.SessionContext;
import com.opengamma.language.context.SessionContextInitializationEventHandler;

/**
 * Debug client deferring calls to a remote process
 */
public class DebugClient extends Client {

  private static final String SESSION_CONTEXT_STASH = "com.opengamma.language.connector.debug.StashMessage";

  protected DebugClient(final ClientContext clientContext, final String inputPipeName, final String outputPipeName,
      final SessionContext session) {
    super(clientContext, inputPipeName, outputPipeName, session);
  }

  @Override
  protected SessionContextInitializationEventHandler getSessionInitializer() {
    final SessionContextInitializationEventHandler superInitializer = super.getSessionInitializer();
    return new SessionContextInitializationEventHandler() {

      @Override
      public void initContext(final MutableSessionContext context) {
        superInitializer.initContext(context);
      }

      @Override
      public void initContextWithStash(final MutableSessionContext context, final FudgeMsg stash) {
        superInitializer.initContextWithStash(context, stash);
        context.setValue(SESSION_CONTEXT_STASH, new ImmutableFudgeMsg(stash, FudgeContext.GLOBAL_DEFAULT));
      }

    };
  }

  private FudgeMsg getStash() {
    return getSessionContext().getValue(SESSION_CONTEXT_STASH);
  }

  @Override
  protected UserMessagePayload dispatchUserMessage(UserMessagePayload message) {
    // TODO pass the message to the external process
    return null;
  }

}

@@ -1728,15 +1728,8 @@
 Msg(
-stash, 
 Fudg
@@ -1751,16 +1751,23 @@
 _DEFAULT
+, stash
 ));%0A    

Enhance FudgeContext and FudgeMsg