@@ -0,0 +1,1741 @@
+package com.github.aureliano.achmed.server;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.net.Socket;%0A%0Aimport com.github.aureliano.achmed.common.exception.AchmedException;%0Aimport com.github.aureliano.achmed.server.service.IService;%0Aimport com.github.aureliano.achmed.server.service.ServiceFactory;%0Aimport com.github.aureliano.achmed.server.service.ServiceType;%0A%0Apublic class ThreadHandler implements Runnable %7B%0A%09%0A%09private static final String SERVICE_PATTERN = %22%5Eservice:%5C%5Cs*%22;%0A%09private static final String SERVICE_NAME_PATTERN = SERVICE_PATTERN + %22(read_file)$%22;%0A%09%0A%09private Socket socket;%0A%09%0A%09public ThreadHandler(Socket socket) %7B%0A%09%09this.socket = socket;%0A%09%7D%0A%09%0A%09@Override%0A%09public void run() %7B%0A%09%09IService service = this.createService();%0A%09%09service.consume(this.socket);%0A%09%7D%0A%09%0A%09private IService createService() %7B%0A%09%09ServiceType type = this.getServiceType();%0A%09%09return ServiceFactory.createService(type);%0A%09%7D%0A%09%0A%09private ServiceType getServiceType() %7B%0A%09%09String serviceName = this.getRequestedService();%0A%09%09try %7B%0A%09%09%09return ServiceType.valueOf(serviceName);%0A%09%09%7D catch (Exception ex) %7B%0A%09%09%09throw new AchmedException(%22There is not a service named %22 + serviceName);%0A%09%09%7D%0A%09%7D%0A%09%0A%09private String getRequestedService() %7B%0A%09%09try %7B%0A%09%09%09BufferedReader reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));%0A%09%09%09String requestedService = reader.readLine();%0A%09%09%0A%09%09%09if (!requestedService.matches(SERVICE_NAME_PATTERN)) %7B%0A%09%09%09%09throw new AchmedException(%22Broken service name description.%22);%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09String serviceName = requestedService.replaceFirst(SERVICE_PATTERN, %22%22).trim();%0A%09%09%09return serviceName.toUpperCase();%0A%09%09%7D catch (IOException ex) %7B%0A%09%09%09throw new AchmedException(ex);%0A%09%09%7D%0A%09%7D%0A%7D

Create thread handler.