<commit_before>/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed 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 net.kuujo.vertigo.output.impl;

import net.kuujo.vertigo.context.ConnectionContext;
import net.kuujo.vertigo.message.JsonMessage;
import net.kuujo.vertigo.message.MessageId;
import net.kuujo.vertigo.output.OutputConnection;
import net.kuujo.vertigo.util.serializer.Serializer;
import net.kuujo.vertigo.util.serializer.SerializerFactory;

import org.vertx.java.core.Vertx;
import org.vertx.java.core.eventbus.EventBus;

/**
 * Default output connection implementation.
 *
 * @author <NAME>
 */
public class DefaultOutputConnection implements OutputConnection {
  private static final Serializer serializer = SerializerFactory.getSerializer(JsonMessage.class);
  private final String address;
  private final EventBus eventBus;

  public DefaultOutputConnection(Vertx vertx, ConnectionContext context) {
    this.eventBus = vertx.eventBus();
    this.address = context.address();
  }

  @Override
  public String address() {
    return address;
  }

  @Override
  public MessageId write(JsonMessage message) {
    eventBus.send(address, serializer.serializeToString(message));
    return message.messageId();
  }

}<commit_msg>Add output connection constructor for tests.<commit_after>/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed 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 net.kuujo.vertigo.output.impl;

import net.kuujo.vertigo.context.ConnectionContext;
import net.kuujo.vertigo.message.JsonMessage;
import net.kuujo.vertigo.message.MessageId;
import net.kuujo.vertigo.output.OutputConnection;
import net.kuujo.vertigo.util.serializer.Serializer;
import net.kuujo.vertigo.util.serializer.SerializerFactory;

import org.vertx.java.core.Vertx;
import org.vertx.java.core.eventbus.EventBus;

/**
 * Default output connection implementation.
 *
 * @author <NAME>
 */
public class DefaultOutputConnection implements OutputConnection {
  private static final Serializer serializer = SerializerFactory.getSerializer(JsonMessage.class);
  private final String address;
  private final EventBus eventBus;

  public DefaultOutputConnection(String address, Vertx vertx) {
    this.address = address;
    this.eventBus = vertx.eventBus();
  }

  public DefaultOutputConnection(Vertx vertx, ConnectionContext context) {
    this.eventBus = vertx.eventBus();
    this.address = context.address();
  }

  @Override
  public String address() {
    return address;
  }

  @Override
  public MessageId write(JsonMessage message) {
    eventBus.send(address, serializer.serializeToString(message));
    return message.messageId();
  }

}
{'fraction_non_alphanumeric': 0.08821932681867535, 'fraction_numerical': 0.004343105320304018, 'mean_word_length': 4.533033033033033, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6745504', 'n_tokens_mistral': 1019, 'n_tokens_neox': 1000, 'n_words': 320}