<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.jcr2spi;

import org.apache.jackrabbit.core.config.RepositoryConfig;
import org.apache.jackrabbit.spi.RepositoryService;
import org.apache.jackrabbit.spi.rmi.remote.RemoteRepositoryService;
import org.apache.jackrabbit.spi.rmi.server.ServerRepositoryService;
import org.apache.jackrabbit.spi2jcr.RepositoryServiceImpl;
import org.apache.jackrabbit.spi2jcr.BatchReadConfig;
import org.apache.log4j.PropertyConfigurator;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;

/**
 * <code>SPIServer</code> starts a jackrabbit repository and wraps it with
 * a SPI2JCR layer and finally makes it available over RMI.
 */
public class SPIServer {

    private static final String REPO_CONFIG = "src/test/resources/repository.xml";

    private static final String REPO_HOME = "target/repo-home";

    private final org.apache.jackrabbit.core.RepositoryImpl repo;

    private final RemoteRepositoryService remoteService;

    private final Registry reg;

    static {
        PropertyConfigurator.configure(SPIServer.class.getClassLoader().getResource("log4j.properties"));
    }

    private SPIServer() throws Exception {
        // start a jackrabbit repository
        System.out.println("Starting Jackrabbit...");
        RepositoryConfig config = RepositoryConfig.create(REPO_CONFIG, REPO_HOME);
        repo = org.apache.jackrabbit.core.RepositoryImpl.create(config);
        System.out.println("Jackrabbit started");
        // wrap with spi2jcr
        // TODO: make BatchReadConfig configurable
        RepositoryService repoService = new RepositoryServiceImpl(repo, new BatchReadConfig());
        System.out.println("Wrapped with SPI2JCR");
        // create spi server
        remoteService = new ServerRepositoryService(repoService);
        System.out.println("Wrapped with SPI-RMI");
        // register server
        reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        reg.bind("spi-server", remoteService);
        System.out.println("Bound to RMI Registry");
    }

    private void shutdown() {
        System.out.println("Shutting down...");
        try {
            reg.unbind("spi-server");
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (NotBoundException e) {
            e.printStackTrace();
        }
        repo.shutdown();
        System.out.println("Jackrabbit stopped");
    }

    public static void main(String[] args) {<commit_msg>- try to setup repository with test data when using SPIServer<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.jcr2spi;

import org.apache.jackrabbit.core.config.RepositoryConfig;
import org.apache.jackrabbit.spi.RepositoryService;
import org.apache.jackrabbit.spi.rmi.remote.RemoteRepositoryService;
import org.apache.jackrabbit.spi.rmi.server.ServerRepositoryService;
import org.apache.jackrabbit.spi2jcr.RepositoryServiceImpl;
import org.apache.jackrabbit.spi2jcr.BatchReadConfig;
import org.apache.log4j.PropertyConfigurator;

import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;

/**
 * <code>SPIServer</code> starts a jackrabbit repository and wraps it with
 * a SPI2JCR layer and finally makes it available over RMI.
 */
public class SPIServer {

    private static final String REPO_CONFIG = "src/test/resources/repository.xml";

    private static final String REPO_HOME = "target/repo-home";

    private final org.apache.jackrabbit.core.RepositoryImpl repo;

    private final RemoteRepositoryService remoteService;

    private final Registry reg;

    static {
        PropertyConfigurator.configure(SPIServer.class.getClassLoader().getResource("log4j.properties"));
    }

    private SPIServer() throws Exception {
        // start a jackrabbit repository
        System.out.println("Starting Jackrabbit...");
        RepositoryConfig config = RepositoryConfig.create(REPO_CONFIG, REPO_HOME);
        repo = org.apache.jackrabbit.core.RepositoryImpl.create(config);
        System.out.println("Jackrabbit started");
        // try to setup test data
        Session s = repo.login(new SimpleCredentials("user", "pass".toCharArray()));
        try {
            RepositorySetup.run(s);
        } finally {
            s.logout();
        }
        // wrap with spi2jcr
        // TODO: make BatchReadConfig configurable
        RepositoryService repoService = new RepositoryServiceImpl(repo, new BatchReadConfig());
        System.out.println("Wrapped with SPI2JCR");
        // create spi server
        remoteService = new ServerRepositoryService(repoService);
        System.out.println("Wrapped with SPI-RMI");
        // register server
        reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        reg.bind("spi-server", remoteService);
        System.out.println("Bound to RMI Registry");
    }

    private void shutdown() {
        System.out.println("Shutting down...");
        try {
            reg.unbind("spi-server");
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (NotBoundException e) {
            e.printStackTrace();
        }
        repo.shutdown();
        System.out.println("Jackrabbit stopped");
    }

    public static void main(String[] args) {
{'fraction_non_alphanumeric': 0.0942484999268257, 'fraction_numerical': 0.0035123664569003364, 'mean_word_length': 3.375160051216389, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3439217', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1788, 'n_words': 522}