/**
* 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 com.perforce.p4camel.producer;
import java.net.URISyntaxException;
import org.apache.camel.EndpointConfiguration;
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.perforce.p4camel.ConnectionFactory;
import com.perforce.p4camel.P4Endpoint;
import com.perforce.p4java.client.IClient;
import com.perforce.p4java.exception.ConfigException;
import com.perforce.p4java.exception.ConnectionException;
import com.perforce.p4java.exception.NoSuchObjectException;
import com.perforce.p4java.exception.ResourceException;
import com.perforce.p4java.server.IOptionsServer;
/**
* The Perforce producer.
*/
public class P4Producer extends DefaultProducer {
private static Logger logger = LoggerFactory.getLogger(P4Producer.class);
private final P4Endpoint endpoint;
private IOptionsServer p4;
private IClient client;
public P4Producer(P4Endpoint endpoint) throws ConnectionException,
NoSuchObjectException, ConfigException, ResourceException,
URISyntaxException {
super(endpoint);
this.endpoint = endpoint;
logger.info("Producer: constructor");
}
@Override
protected void doStart() throws Exception {
super.doStart();
logger.info("Producer: doStart");
p4 = ConnectionFactory.getConnection(endpoint);
p4.connect();
ConnectionFactory.login(p4, endpoint);
}
@Override
protected void doStop() throws Exception {
super.doStop();
logger.info("Producer: doStop");
p4.disconnect();
}
@Override
public void process(Exchange exchange) throws Exception {
logger.info("type: " + endpoint.getType());
logger.info("depotPath: " + endpoint.getDepotPath());
logger.info("user: " + endpoint.getUsername());
logger.info(exchange.getIn().getBody(String.class));
}
}