<commit_before>/*
 * Copyright 2012  Research Studios Austria Forschungsges.m.b.H.
 *
 *    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 won.bot.framework.core.base;

import com.hp.hpl.jena.rdf.model.Model;
import org.springframework.scheduling.TaskScheduler;
import won.bot.framework.core.context.BotContext;
import won.bot.framework.core.event.*;
import won.bot.framework.core.eventlistener.EventListenerContext;
import won.bot.framework.events.EventBus;
import won.bot.framework.events.impl.SchedulerEventBusImpl;
import won.bot.framework.component.needproducer.NeedProducer;
import won.bot.framework.component.nodeurisource.NodeURISource;
import won.protocol.model.ChatMessage;
import won.protocol.model.Connection;
import won.protocol.model.Match;
import won.protocol.owner.OwnerProtocolNeedServiceClientSide;

import java.net.URI;
import java.util.concurrent.Executor;

/**
 *
 */
public class EventBot extends TriggeredBot
{
  private EventBus eventBus;
  private EventListenerContext eventListenerContext = new MyEventListenerContext();

  @Override
  public final void act() throws Exception
  {
    eventBus.publish(new ActEvent());
  }

  @Override
  public final void onMessageFromOtherNeed(final Connection con, final ChatMessage message, final Model content) throws Exception
  {
    eventBus.publish(new MessageFromOtherNeedEvent(con, message, content));
  }

  @Override
  public final void onHintFromMatcher(final Match match, final Model content) throws Exception
  {
    eventBus.publish(new HintFromMatcherEvent(match, content));
  }

  @Override
  public final void onCloseFromOtherNeed(final Connection con, final Model content) throws Exception
  {
    eventBus.publish(new CloseFromOtherNeedEvent(con, content));<commit_msg>improved comments on EventBot<commit_after>/*
 * Copyright 2012  Research Studios Austria Forschungsges.m.b.H.
 *
 *    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 won.bot.framework.core.base;

import com.hp.hpl.jena.rdf.model.Model;
import org.springframework.scheduling.TaskScheduler;
import won.bot.framework.core.context.BotContext;
import won.bot.framework.core.event.*;
import won.bot.framework.core.eventlistener.EventListenerContext;
import won.bot.framework.events.EventBus;
import won.bot.framework.events.impl.SchedulerEventBusImpl;
import won.bot.framework.component.needproducer.NeedProducer;
import won.bot.framework.component.nodeurisource.NodeURISource;
import won.protocol.model.ChatMessage;
import won.protocol.model.Connection;
import won.protocol.model.Match;
import won.protocol.owner.OwnerProtocolNeedServiceClientSide;

import java.net.URI;
import java.util.concurrent.Executor;

/**
 * Base class for bots that define their behaviour through event listeners.
 *
 * All methods from the Bot interface are converted to Events by the EventBot.
 * Subclasses should implement the initializeEventListeners() method to register their
 * event listeners. The corresponding shutdownEventListeners() is called when the bot's
 * shutdown method is called an may be used to perform shutdown work for listeners.
 *
 * An event bot implementation should take care not to do long or blocking work in event
 * listeners. Whenever a long computation or a blocking call is done, it should be
 * done in a Runnable, executed in the Executor (see below).
 *
 * The bot's services and other environment can be accessed in listeners through the
 * instance of EventListenerContext.
 *
 * these services include:
 *
 * <ul>
 *   <li>the event bus - for subscribing for/unsubscribing for/publishing event</li>
 *   <li>the task scheduler - for scheduling tasks (Runnables) to be run after a timeout</li>
 *   <li>the executor - for running tasks (Runnables) immediately in the task scheduler's thread pool</li>
 *   <li>the node uri source - for obtaining a won node URI for need creation</li>
 *   <li>the need producer - for obtaining a valid need content in RDF that can be used to create a need</li>
 *   <li>the owner service - for sending messages to won nodes (create needs, connect, open, message, close) </li>
 *   <li>shutting down the trigger - an event bot may have a trigger that calls the bot's act() method regularly.</li>
 * </ul>
 *
 *
 */
public class EventBot extends TriggeredBot
{
  private EventBus eventBus;
  private EventListenerContext eventListenerContext = new MyEventListenerContext();

  @Override
  public final void act() throws Exception
  {
    eventBus.publish(new ActEvent());
  }

  @Override
  public final void onMessageFromOtherNeed(final Connection con, final ChatMessage message, final Model content) throws Exception
  {
    eventBus.publish(new MessageFromOtherNeedEvent(con, message, content));
  }

  @Override
  public final void onHintFromMatcher(final Match match, final Model content) throws Exception
  {
    eventBus.publish(new HintFromMatcherEvent(match, content));
  }

  @Override
  public final void onCloseFromOtherNeed(final Connection con, final Model content) throws Exception
  {
    eventBus.publish(new CloseFromOtherNeedEvent(con, content));
{'fraction_non_alphanumeric': 0.080078125, 'fraction_numerical': 0.0026041666666666665, 'mean_word_length': 4.418871252204585, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '261004', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1627, 'n_words': 596}