<commit_before>/**
 * Licensed to the Rhiot under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The 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 io.rhiot.component.kura.cloud;

import static io.rhiot.component.kura.cloud.KuraCloudComponent.clientCache;

import io.rhiot.component.kura.utils.KuraServiceFactory;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.eclipse.kura.cloud.CloudClient;
import org.eclipse.kura.cloud.CloudService;

@UriEndpoint(scheme = "kura-cloud", title = "Kura Cloud", label = "iot,kura,cloud", syntax = "kura-cloud:applicationId/appTopic")
public class KuraCloudEndpoint extends DefaultEndpoint {

    @UriParam(defaultValue = "")
    private String applicationId = "";

    @UriParam(defaultValue = "")
    private String topic = "";

    @UriParam(defaultValue = "0")
    private int qos;

    @UriParam(defaultValue = "false")
    private boolean retain = false;

    @UriParam(defaultValue = "5")
    private int priority = 5;

    @UriParam(defaultValue = "false")
    private boolean control = false;

    @UriParam(defaultValue = "")
    private String deviceId;

    private CloudService cloudService;

    public KuraCloudEndpoint(String uri, KuraCloudComponent kuraCloudComponent, CloudService cloudService) {
        super(uri, kuraCloudComponent);
        this.cloudService = cloudService;
    }

    @Override
    public Consumer createConsumer(Processor processor) throws Exception {
        CloudClient cloudClient = clientCache().get(applicationId);
        if (cloudClient == null) {
            cloudClient = getCloudService().newCloudClient(applicationId);
            clientCache().put(applicationId, cloudClient);
        }
        return new KuraCloudConsumer(this, processor, cloudClient);
    }

    @Override
    public KuraCloudProducer createProducer() throws Exception {
        CloudClient cloudClient = clientCache().get(applicationId);
        if (cloudClient == null) {
            cloudClient = getCloudService().newCloudClient(applicationId);
            clientCache().put(applicationId, cloudClient);
        }

        return new KuraCloudProducer(this, cloudClient);
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    @Override
    public KuraCloudComponent getComponent() {
        return (KuraCloudComponent) super.getComponent();
    }

    public String getTopic() {
        return topic;<commit_msg>Improved cache API usage.<commit_after>/**
 * Licensed to the Rhiot under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The 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 io.rhiot.component.kura.cloud;

import static io.rhiot.component.kura.cloud.KuraCloudComponent.clientCache;

import io.rhiot.component.kura.utils.KuraServiceFactory;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.eclipse.kura.cloud.CloudClient;
import org.eclipse.kura.cloud.CloudService;

@UriEndpoint(scheme = "kura-cloud", title = "Kura Cloud", label = "iot,kura,cloud", syntax = "kura-cloud:applicationId/appTopic")
public class KuraCloudEndpoint extends DefaultEndpoint {

    @UriParam(defaultValue = "")
    private String applicationId = "";

    @UriParam(defaultValue = "")
    private String topic = "";

    @UriParam(defaultValue = "0")
    private int qos;

    @UriParam(defaultValue = "false")
    private boolean retain = false;

    @UriParam(defaultValue = "5")
    private int priority = 5;

    @UriParam(defaultValue = "false")
    private boolean control = false;

    @UriParam(defaultValue = "")
    private String deviceId;

    private CloudService cloudService;

    public KuraCloudEndpoint(String uri, KuraCloudComponent kuraCloudComponent, CloudService cloudService) {
        super(uri, kuraCloudComponent);
        this.cloudService = cloudService;
    }

    @Override
    public Consumer createConsumer(Processor processor) throws Exception {
        CloudClient cloudClient = clientCache().getOrCreate(applicationId, cloudService);
        return new KuraCloudConsumer(this, processor, cloudClient);
    }

    @Override
    public KuraCloudProducer createProducer() throws Exception {
        CloudClient cloudClient = clientCache().getOrCreate(applicationId, cloudService);
        return new KuraCloudProducer(this, cloudClient);
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    @Override
    public KuraCloudComponent getComponent() {
        return (KuraCloudComponent) super.getComponent();
    }

    public String getTopic() {
        return topic;
{'fraction_non_alphanumeric': 0.08871099493546807, 'fraction_numerical': 0.002287207972553504, 'mean_word_length': 3.7753510140405617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '2021081', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1595, 'n_words': 496}