Projects >> nuts-and-bolts >>c316779b356c42e1d5d646c7548a0932a4ea3396

Chunk
Conflicting content
  @Provides
  @RequestScoped
<<<<<<< HEAD
  GrizzlyRequest httpRequestContext() {
    Object request = RequestScope.currentRequest();
    if (request == null || !(request instanceof GrizzlyRequest)) {
      throw new IllegalArgumentException("Not a grizzly request");
    }
    return (GrizzlyRequest) request;
=======
  protected GrizzlyRequest httpRequestContext() {
    return RequestScope.currentRequest();
>>>>>>> afcecb1e8b175431f6186c2a4fc7ad8389a1b147
  }

  @Provides
Solution content
  @Provides
  @RequestScoped
  GrizzlyRequest httpRequestContext() {
    Object request = RequestScope.currentRequest();
    if (request == null || !(request instanceof GrizzlyRequest)) {
      throw new IllegalArgumentException("Not a grizzly request");
    }
    return (GrizzlyRequest) request;
  }

  @Provides
File
JerseyGutsModule.java
Developer's decision
Version 1
Kind of conflict
Cast expression
If statement
Method invocation
Method signature
Return statement
Variable
Chunk
Conflicting content
>>>>>>> afcecb1e8b175431f6186c2a4fc7ad8389a1b147
import java.util.ServiceLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
<<<<<<< HEAD
import mx4j.tools.adaptor.http.HttpAdaptor;
=======
import javax.inject.Named;
import javax.inject.Singleton;
import org.slf4j.bridge.SLF4JBridgeHandler;
import ru.hh.nab.grizzly.SimpleGrizzlyWebServer;
import ru.hh.nab.health.limits.LeakDetector;
Solution content
import java.util.ServiceLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
import mx4j.tools.adaptor.http.HttpAdaptor;
import javax.inject.Named;
import javax.inject.Singleton;
import org.slf4j.bridge.SLF4JBridgeHandler;
import ru.hh.nab.grizzly.SimpleGrizzlyWebServer;
import ru.hh.nab.health.limits.LeakDetector;
File
Launcher.java
Developer's decision
Concatenation
Kind of conflict
Import
Chunk
Conflicting content
import com.google.inject.name.Names;
import com.google.inject.util.Providers;
import com.mchange.v2.c3p0.ComboPooledDataSource;
<<<<<<< HEAD
import mx4j.tools.adaptor.http.HttpAdaptor;
=======
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.Path;
>>>>>>> afcecb1e8b175431f6186c2a4fc7ad8389a1b147
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.dbcp.BasicDataSource;
import org.hibernate.ejb.Ejb3Configuration;
Solution content
import com.google.inject.name.Names;
import com.google.inject.util.Providers;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.management.ManagementFactory;
import java.lang.reflect.AnnotatedElement;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.Path;
import mx4j.tools.adaptor.http.HttpAdaptor;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.dbcp.BasicDataSource;
import org.hibernate.ejb.Ejb3Configuration;
File
NabModule.java
Developer's decision
Manual
Kind of conflict
Import
Chunk
Conflicting content
import ru.hh.nab.security.SecureMatcher;
import ru.hh.nab.security.UnauthorizedExceptionJerseyMapper;

<<<<<<< HEAD
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.Path;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.management.ManagementFactory;
import java.lang.reflect.AnnotatedElement;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

=======
>>>>>>> afcecb1e8b175431f6186c2a4fc7ad8389a1b147
@SuppressWarnings("UnusedDeclaration")
public abstract class NabModule extends AbstractModule {
  private final List taskDefs = Lists.newArrayList();
Solution content
import ru.hh.nab.security.SecureMatcher;
import ru.hh.nab.security.UnauthorizedExceptionJerseyMapper;

@SuppressWarnings("UnusedDeclaration")
public abstract class NabModule extends AbstractModule {
  private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
  private final List taskDefs = Lists.newArrayList();
File
NabModule.java
Developer's decision
Manual
Kind of conflict
Import
Chunk
Conflicting content
    bind(GrizzletDefs.class).toInstance(grizzletDefs);
  }

<<<<<<< HEAD
  protected
  @Provides
  @Singleton
  HttpAdaptor httpAdaptor(Settings settings) {
    Properties mx4jProps = settings.subTree("mx4j");
    if ("true".equals(mx4jProps.getProperty("mode"))) {
      try {
        HttpAdaptor adaptor = new HttpAdaptor();
        ObjectName name = new ObjectName("Server:name=HttpAdaptor");
        server.registerMBean(adaptor, name);
        adaptor.setPort(Integer.parseInt(mx4jProps.getProperty("port")));
        adaptor.setHost(mx4jProps.getProperty("host"));
        return adaptor;
      } catch (Exception ex) {
        Logger logger = LoggerFactory.getLogger(HttpAdaptor.class);
        logger.error("Can't create HttpAdaptor: " + ex);
        return null;
      }
    } else {
      return null;
    }
  }

  static class ServletDefs extends ArrayList {
  }

  static class GrizzletDefs extends ArrayList {
  }
  static class ServletDef {
    final Class servlet;
    final String pattern;

    private ServletDef(Class servlet, String pattern) {
      this.servlet = servlet;
      this.pattern = pattern;
    }
  }

  private static class ScheduledTaskDef {
    private final Class klass;
    private final long time;
    private final TimeUnit unit;

    private ScheduledTaskDef(Class klass, long time, TimeUnit unit) {
      this.klass = klass;
      this.time = time;
      this.unit = unit;
    }
  }

  static class GrizzletDef {
    final Class handlerClass;

    public GrizzletDef(Class handlerClass) {
      this.handlerClass = handlerClass;
    }
  }

=======
>>>>>>> afcecb1e8b175431f6186c2a4fc7ad8389a1b147
  protected final void schedulePeriodicTask(Class task, long time, TimeUnit unit) {
    taskDefs.add(new ScheduledTaskDef(task, time, unit));
  }
Solution content
    bind(GrizzletDefs.class).toInstance(grizzletDefs);
  }

  @Provides
  @Singleton
  protected HttpAdaptor httpAdaptor(Settings settings) {
    Properties mx4jProps = settings.subTree("mx4j");
    if ("true".equals(mx4jProps.getProperty("mode"))) {
      try {
        HttpAdaptor adaptor = new HttpAdaptor();
        ObjectName name = new ObjectName("Server:name=HttpAdaptor");
        server.registerMBean(adaptor, name);
        adaptor.setPort(Integer.parseInt(mx4jProps.getProperty("port")));
        adaptor.setHost(mx4jProps.getProperty("host"));
        return adaptor;
      } catch (Exception ex) {
        Logger logger = LoggerFactory.getLogger(HttpAdaptor.class);
        logger.error("Can't create HttpAdaptor: " + ex);
        return null;
      }
    } else {
      return null;
    }
  }

  protected final void schedulePeriodicTask(Class task, long time, TimeUnit unit) {
    taskDefs.add(new ScheduledTaskDef(task, time, unit));
  }
File
NabModule.java
Developer's decision
Manual
Kind of conflict
Class declaration
Method declaration
Chunk
Conflicting content
      return request;
    INSTANCE
  }

<<<<<<< HEAD
  public static class RequestContext {
    protected static final String X_REQUEST_ID = "x-requestContext-id";
    protected static final String X_REQUEST_ID_DEFAULT = "NoRequestIdProvided";
    protected static final String X_HHID_PERFORMER = "x-hhid-performer";
    protected static final String X_HHID_PERFORMER_DEFAULT = "NoPerformerTokenProvided";
    protected static final String X_UID = "x-uid";
    protected static final String X_UID_DEFAULT = "NoUidProvided";
    protected static final String REQ_REMOTE_ADDR = "req.remote-addr";
    protected static final String REQ_REMOTE_ADDR_DEFAULT = "NoRemoteAddrProvided";
    private final String requestId;
    private final String performerToken;
    private final String uid;
    private final String remoteAddr;
    private final Object request;
    public RequestContext(String requestId, String performerToken, String uid, String remoteAddr, Object request)  {
      this.requestId = requestId;
      this.performerToken = performerToken;
      this.uid = uid;
      this.remoteAddr = remoteAddr;
      this.request = request;
    }
    RequestContext(GrizzlyRequest request) {
      this(request.getHeader(X_REQUEST_ID),
          request.getHeader(X_HHID_PERFORMER),
          request.getHeader(X_UID),
          request.getRemoteAddr(),
          request
      );
    }

    public void setLoggingContext() {
      storeValue("req.h." + X_REQUEST_ID, requestId, X_REQUEST_ID_DEFAULT);
      storeValue("req.h." + X_HHID_PERFORMER, performerToken, X_HHID_PERFORMER_DEFAULT);
      storeValue("req.h." + X_UID, uid, X_UID_DEFAULT);
      storeValue(REQ_REMOTE_ADDR, remoteAddr, REQ_REMOTE_ADDR_DEFAULT);
    }
    private void storeValue(String name, String value, String defaultValue) {
      MDC.put(name, value != null ? value : defaultValue);
    }
    public void clearLoggingContext() {
      MDC.clear();
    }
    public Object getRequest() {
    }
  }

  private static final ThreadLocal closure = new ThreadLocal();

  public static void enter(GrizzlyRequest request, TimingsLogger timingsLogger) {
    enter(new RequestContext(request), timingsLogger);
  }

  public static void enter(RequestContext requestContext, TimingsLogger timingsLogger) {
    new RequestScopeClosure(requestContext, timingsLogger).enter();
=======
  public static void enter(GrizzlyRequest req, TimingsLogger timingsLogger) {
    new RequestScopeClosure(req, timingsLogger).enter();
>>>>>>> afcecb1e8b175431f6186c2a4fc7ad8389a1b147
  }
  public static void leave() {
Solution content
    INSTANCE
  }

  public static class RequestContext {
    protected static final String X_REQUEST_ID = "x-requestContext-id";
    protected static final String X_REQUEST_ID_DEFAULT = "NoRequestIdProvided";
    protected static final String X_HHID_PERFORMER = "x-hhid-performer";
    protected static final String X_HHID_PERFORMER_DEFAULT = "NoPerformerTokenProvided";
    protected static final String X_UID = "x-uid";
    protected static final String X_UID_DEFAULT = "NoUidProvided";
    protected static final String REQ_REMOTE_ADDR = "req.remote-addr";
    protected static final String REQ_REMOTE_ADDR_DEFAULT = "NoRemoteAddrProvided";
    private final String requestId;
    private final String performerToken;
    private final String uid;
    private final String remoteAddr;
    private final Object request;
    public RequestContext(String requestId, String performerToken, String uid, String remoteAddr, Object request)  {
      this.requestId = requestId;
      this.performerToken = performerToken;
      this.uid = uid;
      this.remoteAddr = remoteAddr;
      this.request = request;
    }
    RequestContext(GrizzlyRequest request) {
      this(request.getHeader(X_REQUEST_ID),
          request.getHeader(X_HHID_PERFORMER),
          request.getHeader(X_UID),
          request.getRemoteAddr(),
          request
      );
    }

    public void setLoggingContext() {
      storeValue("req.h." + X_REQUEST_ID, requestId, X_REQUEST_ID_DEFAULT);
      storeValue("req.h." + X_HHID_PERFORMER, performerToken, X_HHID_PERFORMER_DEFAULT);
      storeValue("req.h." + X_UID, uid, X_UID_DEFAULT);
      storeValue(REQ_REMOTE_ADDR, remoteAddr, REQ_REMOTE_ADDR_DEFAULT);
    }
    private void storeValue(String name, String value, String defaultValue) {
      MDC.put(name, value != null ? value : defaultValue);
    }
    public void clearLoggingContext() {
      MDC.clear();
    }
    public Object getRequest() {
      return request;
    }
  }

  public static void enter(GrizzlyRequest request, TimingsLogger timingsLogger) {
    enter(new RequestContext(request), timingsLogger);
  }

  public static void enter(RequestContext requestContext, TimingsLogger timingsLogger) {
    new RequestScopeClosure(requestContext, timingsLogger).enter();
  }

  public static void leave() {
File
RequestScope.java
Developer's decision
Combination
Kind of conflict
Attribute
Class declaration
Method declaration
Method invocation
Method signature
Chunk
Conflicting content
    RequestScopeClosure cls = closure.get();
    if (cls == null) {
      throw new OutOfScopeException("Out of RequestScope");
<<<<<<< HEAD
    return cls.requestContext.getRequest();
=======
    }
    return cls.request;
>>>>>>> afcecb1e8b175431f6186c2a4fc7ad8389a1b147
  }

  public static RequestScopeClosure currentClosure() {
Solution content
    if (cls == null) {
    RequestScopeClosure cls = closure.get();
      throw new OutOfScopeException("Out of RequestScope");
    }
    return cls.requestContext.getRequest();
  }

  public static RequestScopeClosure currentClosure() {
File
RequestScope.java
Developer's decision
Combination
Kind of conflict
Method invocation
Return statement
Variable
Chunk
Conflicting content
  }

  public static class RequestScopeClosure implements ScopeClosure {
<<<<<<< HEAD

    private final RequestContext requestContext;
=======
    private static final String X_REQUEST_ID = "x-request-id";
    private static final String X_HHID_PERFORMER = "x-hhid-performer";
    private static final String X_UID = "x-uid";
    private static final String REQ_REMOTE_ADDR = "req.remote-addr";

    private final GrizzlyRequest request;
>>>>>>> afcecb1e8b175431f6186c2a4fc7ad8389a1b147
    private final TimingsLogger timingsLogger;
    private final Map, Object> objects = Maps.newHashMap();
Solution content
  }

  public static class RequestScopeClosure implements ScopeClosure {

    private final RequestContext requestContext;
    private final TimingsLogger timingsLogger;
    private final Map, Object> objects = Maps.newHashMap();
File
RequestScope.java
Developer's decision
Version 1
Kind of conflict
Attribute