// Path: src/main/java/de/danielbasedow/prospecter/core/Instance.java
// public class Instance {
//     private final String homeDirectory;
//     private static final Logger LOGGER = LoggerFactory.getLogger(Instance.class);
//     private final Map<String, Schema> schemas;
// 
//     public Instance(String homeDirectory) {
//         this.homeDirectory = homeDirectory;
//         schemas = new HashMap<String, Schema>();
//     }
// 
//     public void initialize() throws SchemaConfigurationError {
//         File dir = new File(homeDirectory);
//         if (!dir.isDirectory() || !dir.canRead()) {
//             LOGGER.error("Can't open home directory '" + homeDirectory + "' make sure it is a directory and readable.");
//             throw new SchemaConfigurationError("Can't read home directory");
//         }
// 
//         File[] files = dir.listFiles();
//         if (files == null) {
//             LOGGER.error("Error reading home directory. Make sure it is not empty.");
//             throw new SchemaConfigurationError("No files in home directory");
//         }
//         for (File file : files) {
//             if (file.isDirectory() && file.canRead()) {
//                 File[] schemaFiles = file.listFiles(new FilenameFilter() {
//                     @Override
//                     public boolean accept(File dir, String name) {
//                         return "schema.json".equals(name);
//                     }
//                 });
//                 if (schemaFiles.length == 1) {
//                     LOGGER.info("Found schema.json in '" + file.getAbsoluteFile() + "'");
//                     //directory name is schema name
//                     String schemaName = file.getName();
//                     SchemaBuilder schemaBuilder = new SchemaBuilderJSON(schemaFiles[0]);
//                     schemas.put(schemaName, schemaBuilder.getSchema());
//                 }
//             }
//         }
//     }
// 
//     public void shutDown() {
//         for (Map.Entry<String, Schema> entry : schemas.entrySet()) {
//             Schema schema = entry.getValue();
//             if (schema != null) {
//                 schema.close();
//             }
//         }
//     }
// 
//     public Schema getSchema(String name) {
//         Schema schema = schemas.get(name);
//         if (schema == null) {
//             throw new SchemaNotFoundException("Schema '" + name + "' unknown.");
//         }
//         return schema;
//     }
// }
// 
// Path: src/main/java/de/danielbasedow/prospecter/core/schema/SchemaConfigurationError.java
// public class SchemaConfigurationError extends Exception {
//     public SchemaConfigurationError(String msg) {
//         super(msg);
//     }
// 
//     public SchemaConfigurationError(String msg, Throwable cause) {
//         super(msg, cause);
//     }
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import de.danielbasedow.prospecter.core.Instance;
import de.danielbasedow.prospecter.core.schema.SchemaConfigurationError;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
package de.danielbasedow.prospecter.server;



public class Server {
    private static final Logger LOGGER = LoggerFactory.getLogger(Server.class);

    public static void main(String[] args) {
        ObjectMapper mapper = new ObjectMapper();
        ServerConfig config;
        try {
            config = mapper.readValue(new File(args[0]), ServerConfig.class);
        } catch (IOException e) {
            LOGGER.error("unable to read config file '" + args[0] + "'", e);
            return;
        }

// Path: src/main/java/de/danielbasedow/prospecter/core/Instance.java
// public class Instance {
//     private final String homeDirectory;
//     private static final Logger LOGGER = LoggerFactory.getLogger(Instance.class);
//     private final Map<String, Schema> schemas;
// 
//     public Instance(String homeDirectory) {
//         this.homeDirectory = homeDirectory;
//         schemas = new HashMap<String, Schema>();
//     }
// 
//     public void initialize() throws SchemaConfigurationError {
//         File dir = new File(homeDirectory);
//         if (!dir.isDirectory() || !dir.canRead()) {
//             LOGGER.error("Can't open home directory '" + homeDirectory + "' make sure it is a directory and readable.");
//             throw new SchemaConfigurationError("Can't read home directory");
//         }
// 
//         File[] files = dir.listFiles();
//         if (files == null) {
//             LOGGER.error("Error reading home directory. Make sure it is not empty.");
//             throw new SchemaConfigurationError("No files in home directory");
//         }
//         for (File file : files) {
//             if (file.isDirectory() && file.canRead()) {
//                 File[] schemaFiles = file.listFiles(new FilenameFilter() {
//                     @Override
//                     public boolean accept(File dir, String name) {
//                         return "schema.json".equals(name);
//                     }
//                 });
//                 if (schemaFiles.length == 1) {
//                     LOGGER.info("Found schema.json in '" + file.getAbsoluteFile() + "'");
//                     //directory name is schema name
//                     String schemaName = file.getName();
//                     SchemaBuilder schemaBuilder = new SchemaBuilderJSON(schemaFiles[0]);
//                     schemas.put(schemaName, schemaBuilder.getSchema());
//                 }
//             }
//         }
//     }
// 
//     public void shutDown() {
//         for (Map.Entry<String, Schema> entry : schemas.entrySet()) {
//             Schema schema = entry.getValue();
//             if (schema != null) {
//                 schema.close();
//             }
//         }
//     }
// 
//     public Schema getSchema(String name) {
//         Schema schema = schemas.get(name);
//         if (schema == null) {
//             throw new SchemaNotFoundException("Schema '" + name + "' unknown.");
//         }
//         return schema;
//     }
// }
// 
// Path: src/main/java/de/danielbasedow/prospecter/core/schema/SchemaConfigurationError.java
// public class SchemaConfigurationError extends Exception {
//     public SchemaConfigurationError(String msg) {
//         super(msg);
//     }
// 
//     public SchemaConfigurationError(String msg, Throwable cause) {
//         super(msg, cause);
//     }
// }


// Path: src/main/java/de/danielbasedow/prospecter/server/Server.java
import com.fasterxml.jackson.databind.ObjectMapper;
import de.danielbasedow.prospecter.core.Instance;
import de.danielbasedow.prospecter.core.schema.SchemaConfigurationError;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;

package de.danielbasedow.prospecter.server;



public class Server {
    private static final Logger LOGGER = LoggerFactory.getLogger(Server.class);

    public static void main(String[] args) {
        ObjectMapper mapper = new ObjectMapper();
        ServerConfig config;
        try {
            config = mapper.readValue(new File(args[0]), ServerConfig.class);
        } catch (IOException e) {
            LOGGER.error("unable to read config file '" + args[0] + "'", e);
            return;
        }

        final Instance instance = new Instance(config.getHomeDir());