Package com.asakusafw.bulkloader.transfer

Examples of com.asakusafw.bulkloader.transfer.FileProtocol


            FileList.Writer output) throws BulkLoaderSystemException {
        assert input != null;
        assert output != null;
        try {
            while (input.next()) {
                FileProtocol protocol = input.getCurrentProtocol();
                if (protocol.getKind() != FileProtocol.Kind.GET_CACHE_INFO) {
                    throw new IOException(MessageFormat.format(
                            "Unexpected protocol kind in GetCacheInfo: {0}",
                            protocol.getKind(),
                            protocol.getLocation()));
                }
                LOG.info("TG-GETCACHE-01006", protocol.getLocation());
                CacheInfo info = getCacheInfo(protocol.getLocation());
                FileProtocol result;
                if (info == null) {
                    result = new FileProtocol(FileProtocol.Kind.RESPONSE_NOT_FOUND, protocol.getLocation(), null);
                    LOG.info("TG-GETCACHE-01008", protocol.getLocation());
                } else {
                    result = new FileProtocol(FileProtocol.Kind.RESPONSE_CACHE_INFO, protocol.getLocation(), info);
                    LOG.info("TG-GETCACHE-01007",
                            protocol.getLocation(),
                            info.getId(),
                            info.getTableName(),
                            info.getTimestamp().getTime());
View Full Code Here


        }
        try {
            // FileListの終端まで繰り返す
            List<Future<?>> running = new ArrayList<Future<?>>();
            while (reader.next()) {
                FileProtocol protocol = reader.getCurrentProtocol();
                InputStream content = reader.openContent();
                try {
                    switch (protocol.getKind()) {
                    case CONTENT:
                        importContent(protocol, content, bean, user);
                        break;

                    case CREATE_CACHE:
                    case UPDATE_CACHE:
                        long recordCount = putCachePatch(protocol, content, bean, user);
                        Callable<?> builder = createCacheBuilder(protocol, bean, user, recordCount);
                        if (builder != null) {
                            LOG.debugMessage("Submitting cache builder: {0} {1}",
                                    protocol.getKind(),
                                    protocol.getInfo().getTableName());
                            running.add(executor.submit(builder));
                        }
                        break;

                    default:
                        throw new AssertionError(protocol.getKind());
                    }
                } finally {
                    content.close();
                }
            }
View Full Code Here

            // プロファイル用のテーブル
            Map<String, TableTransferProfile> profiles = new TreeMap<String, TableTransferProfile>();

            while (reader.next()) {
                FileProtocol protocol = reader.getCurrentProtocol();
                assert protocol.getKind() == FileProtocol.Kind.CONTENT;

                // ファイル名を取得
                String fileName = protocol.getLocation();

                // テーブル名を取得
                String tableName = FileNameUtil.getExportTableName(fileName);
                if (tableName == null) {
                    LOG.error("TG-EXPORTER-02003", fileName, "(Unknown)");
                    return false;
                } else if (bean.getExportTargetTable(tableName) == null) {
                    LOG.error("TG-EXPORTER-02003", fileName, tableName);
                    return false;
                }

                // プロファイル情報の引当
                TableTransferProfile profile = profiles.get(tableName);
                if (profile == null) {
                    profile = new TableTransferProfile(tableName);
                    profiles.put(tableName, profile);
                }

                // ファイル名を作成
                File file = FileNameUtil.createExportFilePath(
                        fileDirectry,
                        bean.getTargetName(),
                        bean.getJobflowId(),
                        bean.getExecutionId(),
                        tableName,
                        fileSeq++);

                // ファイルを読み込んでローカルファイルに書き込む
                LOG.info("TG-EXPORTER-02008", tableName, file.getAbsolutePath());

                long dumpStartTime = System.currentTimeMillis();
                long dumpFileSize = 0;

                int byteSize = Integer.parseInt(
                        ConfigurationLoader.getProperty(Constants.PROP_KEY_EXP_FILE_COMP_BUFSIZE));
                byte[] b = new byte[byteSize];

                InputStream content = reader.openContent();
                OutputStream fos = null;
                try {
                    fos = createFos(file);
                    while (true) {
                        int read;
                        try {
                            read = content.read(b);
                        } catch (IOException e) {
                            throw new BulkLoaderSystemException(e, getClass(), "TG-EXPORTER-02002",
                                    "Exportファイルの読み込みに失敗。エントリ名:" + protocol.getLocation());
                        }
                        // 入力ファイルの終端を察知する
                        if (read < 0) {
                            break;
                        }
View Full Code Here

        bean.setExecutionId(executionId);

        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        FileList.Writer writer = FileList.createWriter(buffer, true);
        final CacheInfo info = new CacheInfo("a", "c1", Calendar.getInstance(), "IMPORT_TARGET1", Arrays.asList("a", "b"), "X", 0);
        writer.openNext(new FileProtocol(
                FileProtocol.Kind.CREATE_CACHE,
                tableBean1.getDfsFilePath(),
                info)
        ).close();
        writer.openNext(new FileProtocol(
                FileProtocol.Kind.CONTENT,
                FileNameUtil.createSendImportFileName("IMPORT_TARGET2"),
                null)
        ).close();
        writer.close();
View Full Code Here

        bean.setExecutionId(executionId);

        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        FileList.Writer writer = FileList.createWriter(buffer, true);
        final CacheInfo info = new CacheInfo("a", "c1", Calendar.getInstance(), "IMPORT_TARGET1", Arrays.asList("a", "b"), "X", 0);
        writer.openNext(new FileProtocol(
                FileProtocol.Kind.UPDATE_CACHE,
                tableBean1.getDfsFilePath(),
                info)
        ).close();
        writer.openNext(new FileProtocol(
                FileProtocol.Kind.CONTENT,
                FileNameUtil.createSendImportFileName("IMPORT_TARGET2"),
                null)
        ).close();
        writer.close();
View Full Code Here

    private FileList.Reader prepare(String... locations) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        FileList.Writer writer = FileList.createWriter(output, false);
        for (String location : locations) {
            writer.openNext(new FileProtocol(FileProtocol.Kind.GET_CACHE_INFO, location, null)).close();
        }
        writer.close();
        return FileList.createReader(new ByteArrayInputStream(output.toByteArray()));
    }
View Full Code Here

            FileList.Writer output) throws BulkLoaderSystemException {
        assert input != null;
        assert output != null;
        try {
            while (input.next()) {
                FileProtocol protocol = input.getCurrentProtocol();
                if (protocol.getKind() != FileProtocol.Kind.DELETE_CACHE) {
                    throw new IOException(MessageFormat.format(
                            "Unexpected protocol kind in DeleteCacheStorage: {0}",
                            protocol.getKind(),
                            protocol.getLocation()));
                }
                LOG.info("TG-GCCACHE-03006", protocol.getLocation());
                FileProtocol.Kind result = deleteCacheData(protocol.getLocation());
                LOG.info("TG-GCCACHE-03007", protocol.getLocation(), result);
                FileProtocol response = new FileProtocol(result, protocol.getLocation(), null);
                output.openNext(response).close();
            }
        } catch (IOException e) {
            throw new BulkLoaderSystemException(e, getClass(), "TG-GCCACHE-03005",
                    targetName, userName);
View Full Code Here

            @Override
            public Void call() throws IOException {
                FileList.Writer writer = provider.openWriter(false);
                try {
                    for (LocalCacheInfo info : list) {
                        FileProtocol protocol = new FileProtocol(
                                FileProtocol.Kind.DELETE_CACHE,
                                info.getPath(),
                                null);

                        writer.openNext(protocol).close();
View Full Code Here

            public Map<String, FileProtocol.Kind> call() throws IOException {
                Map<String, FileProtocol.Kind> results = new HashMap<String, FileProtocol.Kind>();
                FileList.Reader reader = provider.openReader();
                try {
                    while (reader.next()) {
                        FileProtocol protocol = reader.getCurrentProtocol();

                        // receive only header
                        reader.openContent().close();

                        switch (protocol.getKind()) {
                        case RESPONSE_DELETED:
                        case RESPONSE_NOT_FOUND:
                        case RESPONSE_ERROR:
                            results.put(protocol.getLocation(), protocol.getKind());
                            break;
                        default:
                            throw new IOException(MessageFormat.format(
                                    "Unknown protocol in response: {0}",
                                    protocol));
View Full Code Here

    private FileList.Reader prepare(String... locations) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        FileList.Writer writer = FileList.createWriter(output, false);
        for (String location : locations) {
            writer.openNext(new FileProtocol(FileProtocol.Kind.DELETE_CACHE, location, null)).close();
        }
        writer.close();
        return FileList.createReader(new ByteArrayInputStream(output.toByteArray()));
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.bulkloader.transfer.FileProtocol

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.