Package org.apache.marmotta.platform.backend.http

Source Code of org.apache.marmotta.platform.backend.http.HTTPStoreProvider

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* 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.marmotta.platform.backend.http;

import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.apache.marmotta.platform.core.api.triplestore.StoreProvider;
import org.openrdf.repository.http.HTTPRepository;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.NotifyingSail;
import org.openrdf.sail.Sail;
import org.openrdf.sail.federation.Federation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

/**
* A triple store provider for Sesame HTTP repositories.
*
* @author Sebastian Schaffert (sschaffert@apache.org)
*/
@ApplicationScoped
public class HTTPStoreProvider implements StoreProvider {

    private static Logger log = LoggerFactory.getLogger(HTTPStoreProvider.class);

    @Inject
    private ConfigurationService configurationService;


    private HTTPRepository httpRepository;

    /**
     * Create the repository using the sail given as argument. This method is needed because some backends
     * use custom implementations of SailRepository.
     *
     * @param sail
     * @return
     */
    @Override
    public SailRepository createRepository(Sail sail) {
        return new SailRepository(sail);
    }

    /**
     * Create the store provided by this SailProvider
     *
     * @return a new instance of the store
     */
    @Override
    public NotifyingSail createStore() {
        String serverUrl = configurationService.getStringConfiguration("backend.http.url");
        if(serverUrl == null) {
            throw new IllegalStateException("no server URL defined for HTTP backend (property backend.http.url)");
        }

        log.info("creating new HTTP repository client for server at {}", serverUrl);

        httpRepository = new HTTPRepository(serverUrl);

        // TODO: would be better to implement a RepositorySail as NotifyingSail wrapper around a repository
        Federation store = new Federation();
        store.addMember(httpRepository);

        return (NotifyingSail)store;
    }

    /**
     * Return the name of the provider. Used e.g. for displaying status information or logging.
     *
     * @return
     */
    @Override
    public String getName() {
        return "Memory Store";
    }

    /**
     * Return true if this sail provider is enabled in the configuration.
     *
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
TOP

Related Classes of org.apache.marmotta.platform.backend.http.HTTPStoreProvider

TOP
Copyright © 2018 www.massapi.com. 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.