text:
There're sometimes when we want to test something and we just need to serve static files on the web. This repository is meant for that!

# Usage

1. Clone this repository
2. Run `heroku create --app your-name`
3. Add any files you want :).
4. `git push heroku master`

You don't need to install anything.

Whatever file you've added to this folder will get served. For example, as there's a `index.html` created as an example, you can just go to that URL and that file will be shown. As simple as that

Try going to [https://static-file-server.herokuapp.com/](https://static-file-server.herokuapp.com/) and [https://static-file-server.herokuapp.com/sub-path/hi.json](https://static-file-server.herokuapp.com/sub-path/hi.json)

# Licence

MIT


text:
package org.opensingular.requirement.commons;

import org.opensingular.app.commons.spring.persistence.SingularPersistenceDefaultBeanFactory;
import org.opensingular.requirement.module.config.AbstractSingularInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

public class CommonsInitializerMock extends AbstractSingularInitializer {
    public static final String TESTE = "GRUPO_TESTE";
    private AnnotationConfigWebApplicationContext applicationContext;

    public CommonsInitializerMock(AnnotationConfigWebApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public CommonsInitializerMock() {
    }

    @Override
    protected String[] getSpringPackagesToScan() {
        return new String[0];
    }

    @Override
    public AnnotationConfigWebApplicationContext createApplicationContext() {
        return applicationContext;
    }

    @Override
    protected Class<? extends SingularPersistenceDefaultBeanFactory> getSingularPersistenceConfigurationBeanFactoryClass() {
        return SingularPersistenceDefaultBeanFactory.class;
    }
}

redpajama_set_name: RedPajamaGithub


text:
import { CreateExhibitDialogComponent } from './../create-exhibit-dialog/create-exhibit-dialog.component';
import { User } from './../../../users/user.model';
import { UserService } from './../../../users/user.service';
import { AuthServiceComponent } from './../../../authentication/auth.service';
import { Component, OnInit, Output } from '@angular/core';
import { MdDialog, MdDialogRef } from '@angular/material';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { TranslateService } from 'ng2-translate';

import { } from 'googlemaps';
import { MapsAPILoader } from '@agm/core';

import { ConfirmDeleteDialogComponent } from './../../shared/confirm-delete-dialog/confirm-delete-dialog.component';
import { ExhibitService } from './.././shared/exhibit.service';
import { Exhibit } from './.././shared/exhibit.model';
import { MediaService } from './../../media/shared/media.service';
import { Route } from './../../routes/shared/route.model';
import { RouteService } from './../../routes/shared/routes.service';
import { Status } from './../../shared/status.model';
import { SupervisorGuard } from './../../../shared/guards/supervisor-guard';
import { Tag } from './../../tags/shared/tag.model';
import { TagService } from './../../tags/shared/tag.service';

@Component({
  moduleId: module.id,
  selector: 'hip-exhibits',
  styleUrls: ['my-exhibits.component.css'],
  templateUrl: 'my-exhibits.component.html'
})

export class MyExhibitsComponent implements OnInit {
  allExhibits: Exhibit[];
  exhibits: Exhibit[];
  existingTags: Tag[];
  previews = new Map<number, SafeUrl>();
  previewsLoaded = false;
  routes: Route[];
  statuses = Status.getValuesForSearch();
  isSupervisor: boolean;
  inDeletedPage: boolean;
  getExhibitId = 0;
  private exhibitCache = new Map<number, Exhibit[]>();
  @Output() rating: number;

  errorMessage = '';
  private currentUser = User.getEmptyUser();
  loggedIn: boolean;
  matches: any = [];

  // search parameters
  searchQuery = '';
  selectedStatus = 'ALL';
  selectedRoute = -1;
  showingSearchResults = false;

  // pagination parameters
  exhibitsPerPage = 10;
  currentPage = 1;
  totalItems: number;

  // map parameters
  lat = 51.718990;
  lng = 8.754736;
  maxNumberOfMarkers = 10000;

  // dialogs
  private createDialogRef: MdDialogRef<CreateExhibitDialogComponent>;
  private deleteDialogRef: MdDialogRef<ConfirmDeleteDialogComponent>;

  constructor(private dialog: MdDialog,
    private exhibitService: ExhibitService,
    private mediaService: MediaService,
    public router: Router,
    private routeService: RouteService,
    private sanitizer: DomSanitizer,
    private tagService: TagService,
    private toasterService: ToasterService,
    private translateService: TranslateService,
    private supervisorGuard: SupervisorGuard,
    private authService: AuthServiceComponent,
    private userService: UserService) {
}

  ngOnInit() {
    this.getIsSupervisor();
    let allRoutesOption = Route.emptyRoute();
    allRoutesOption.title = 'ALL';
    this.routes = [allRoutesOption];

    this.getMyExhibits();

    this.routeService.getAllRoutes(1, 100)
      .then(
      data => this.routes = this.routes.concat(data.items)
      ).catch(
      error => console.error(error)
      );

    this.getPage(1);

    this.loggedIn = this.authService.isLoggedIn();
    if (this.loggedIn) {
      this.userService.getCurrent().then(
        (data: any) => {
          this.currentUser = <User> data;
        },
        (error: any) => this.errorMessage = <any> error
      );
    }
  }

  getIsSupervisor() {
    this.supervisorGuard.isSupervisor().then(
      (response: boolean) => {
        this.isSupervisor = response;
      });
  }

  getTagNames() {
    let tagArray = '';
    for (let i = 0; i < this.exhibits.length; i++) {
      for (let j = 0; j < this.exhibits[i].tags.length; j++) {
        if (tagArray.indexOf(this.exhibits[i].tags[j]) === -1) {
          tagArray = tagArray + '&IncludeOnly=' + this.exhibits[i].tags[j] + '&';
        }
      }
    }
    this.tagService.getAllTags(1, 50, 'ALL', '', 'id', tagArray).then(
      response => {
        this.existingTags = response.items;
        for (let i = 0; i < this.exhibits.length; i++) {
          for (let j = 0; j < this.exhibits[i].tags.length; j++) {
            let index = this.existingTags.map(function (x: Tag) { return x.id; }).indexOf(this.exhibits[i].tags[j]);
            this.exhibits[i].tags[j] = this.existingTags[index].title;
          }
        }
      }
    ).catch(
      error => this.toasterService.pop('error', this.translate('Error while saving'), error)
      );
  }

  getPage(page: number) {
    if (this.exhibitCache.has(page)) {
      this.exhibits = this.exhibitCache.get(page);
      this.currentPage = page;
    } else {
      let status = this.inDeletedPage ? 'Deleted' : this.selectedStatus;
      this.exhibitService.getMyExhibits(page, this.exhibitsPerPage, status,
        this.searchQuery, 'id', 'undefined', this.selectedRoute !== -1 ? [this.selectedRoute] : undefined)
        .then(
        data => {
          this.exhibits = data.items;
          this.totalItems = data.total;
          this.currentPage = page;
          this.exhibitCache.set(this.currentPage, this.exhibits);
          this.getTagNames();
          this.loadPreviews();
          this.getAllExhibitsRating();
        }
        ).catch(
        error => console.error(error)
        );
    }
  }

  createExhibit() {
    let context = this;
    this.createDialogRef = this.dialog.open(CreateExhibitDialogComponent, { width: '45em' });
    this.createDialogRef.afterClosed().subscribe(
      (newExhibit: Exhibit) => {
        if (newExhibit.latitude) { newExhibit.latitude = newExhibit.latitude.toString().replace(/,/g, '.'); }
        if (newExhibit.longitude) { newExhibit.longitude = newExhibit.longitude.toString().replace(/,/g, '.'); }
        if (newExhibit) {
          this.exhibitService.createExhibit(newExhibit)
            .then(
            () => {
              this.toasterService.pop('success', this.translate('exhibit saved'));
              setTimeout(function () {
                context.reloadList();
              }, 1000);
            }
            ).catch(
            error => this.toasterService.pop('error', this.translate('Error while saving'), error)
            );
        }
        this.createDialogRef = null;
      }
    );
  }

  deleteExhibit(exhibit: Exhibit) {
    let context = this;
    this.deleteDialogRef = this.dialog.open(ConfirmDeleteDialogComponent, {
      data: {
        title: this.translateService.instant('delete exhibit'),
        message: this.translateService.instant('confirm delete exhibit', { name: exhibit.name })
      }
    });
    this.deleteDialogRef.afterClosed().subscribe(
      (confirmed: boolean) => {
        if (confirmed) {
          this.exhibitService.deleteExhibit(exhibit.id)
            .then(
            () => {
              this.toasterService.pop('success', 'Success', exhibit.name + ' - ' + this.translate('exhibit deleted'));
              setTimeout(function () {
                context.reloadList();
              }, 1000);
            }
            ).catch(
            error => this.toasterService.pop('error', this.translate('Error while saving'), error)
            );
        }
      }
    );
  }

  getAllExhibitsRating() {
    for (let j = 0; j < this.exhibits.length; j++) {
      this.exhibitService.getExhibitRating(this.exhibits[j].id)
        .then(
        data => {
          this.exhibits[j].ratings = data.average;
        }
        ).catch(
        error => console.error(error)
        );
    }
  }

  findExhibits() {
    if (this.searchQuery.trim().length >= 3) {
      this.exhibits = undefined;
      this.exhibitCache.clear();
      this.getPage(1);
      this.showingSearchResults = true;
    } else if (this.searchQuery.trim().length < 1) {
      this.resetSearch();
    }
  }

  getMyExhibits(query?: string) {
    this.exhibitService.getMyExhibits(1, this.maxNumberOfMarkers)
      .then(data => this.allExhibits = data.items);
  }

  reloadList() {
    this.exhibits = undefined;
    this.exhibitCache.clear();
    this.getPage(1);
  }

  resetSearch() {
    this.searchQuery = '';
    this.exhibits = undefined;
    this.exhibitCache.clear();
    this.getPage(1);
    this.showingSearchResults = false;
  }

  isDraft(exhibit: Exhibit) {
    return exhibit.status === 'DRAFT';
  }

  getOpacity(exhibit: Exhibit): number {
    if (exhibit.status === 'DRAFT') {
      return 0.5;
    } else {
      return 1;
    }
  }

  private loadPreviews() {
    let previewable = this.exhibits.filter(exhibit => exhibit.image != null && !this.previews.has(exhibit.id));
    previewable.forEach(
      exhibit => {
        this.mediaService.downloadFile(exhibit.image, true)
          .then(
          (response: any) => {
            let reader = new FileReader();
            reader.readAsDataURL(response);
            reader.onloadend = () => {
              this.previews.set(exhibit.id, this.sanitizer.bypassSecurityTrustUrl(reader.result));
              this.previewsLoaded = previewable.every(ex => this.previews.has(ex.id));
            };
          }
          ).catch(
          error => {
            previewable.splice(previewable.findIndex(ex => ex.id === exhibit.id), 1);
            this.previewsLoaded = previewable.every(ex => this.previews.has(ex.id));
          }
          );
      }
    );
  }

  private translate(data: string): string {
    let translatedResponse: string;
    this.translateService.get(data).subscribe(
      (value: string) => {
        translatedResponse = value;
      }
    );
    return translatedResponse;
  }
}


text:
package com.intellij.psi.impl.source.codeStyle;

import com.intellij.openapi.components.RoamingType;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.options.BaseSchemeProcessor;
import com.intellij.openapi.options.SchemeProcessor;
import com.intellij.openapi.options.SchemesManager;
import com.intellij.openapi.options.SchemesManagerFactory;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.codeStyle.CodeStyleScheme;
import com.intellij.psi.codeStyle.CodeStyleSchemes;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

public abstract class CodeStyleSchemesImpl extends CodeStyleSchemes {
  @NonNls public static final String DEFAULT_SCHEME_NAME = "Default";

  @SuppressWarnings("SpellCheckingInspection")
  static final String CODE_STYLES_DIR_PATH = StoragePathMacros.ROOT_CONFIG + "/codestyles";

  public String CURRENT_SCHEME_NAME = DEFAULT_SCHEME_NAME;
  private boolean myIsInitialized = false;

  private final SchemesManager<CodeStyleScheme, CodeStyleSchemeImpl> mySchemesManager;

  public CodeStyleSchemesImpl(SchemesManagerFactory schemesManagerFactory) {
    SchemeProcessor<CodeStyleSchemeImpl> processor = new BaseSchemeProcessor<CodeStyleSchemeImpl>() {
      @NotNull
      @Override
      public CodeStyleSchemeImpl readScheme(@NotNull Element element) {
        return CodeStyleSchemeImpl.readScheme(element);
      }

      @Override
      public Element writeScheme(@NotNull final CodeStyleSchemeImpl scheme) throws WriteExternalException {
        return scheme.saveToDocument();
      }

      @Override
      public boolean shouldBeSaved(@NotNull final CodeStyleSchemeImpl scheme) {
        return !scheme.isDefault();
      }

      @Override
      public void initScheme(@NotNull final CodeStyleSchemeImpl scheme) {
        scheme.init(CodeStyleSchemesImpl.this);
      }
    };

    mySchemesManager = schemesManagerFactory.createSchemesManager(CODE_STYLES_DIR_PATH, processor, RoamingType.PER_USER);

    init();
    addScheme(new CodeStyleSchemeImpl(DEFAULT_SCHEME_NAME, true, null));
    setCurrentScheme(getDefaultScheme());
  }

  @Override
  public CodeStyleScheme[] getSchemes() {
    Collection<CodeStyleScheme> schemes = mySchemesManager.getAllSchemes();
    return schemes.toArray(new CodeStyleScheme[schemes.size()]);
  }

  @Override
  public CodeStyleScheme getCurrentScheme() {
    return mySchemesManager.getCurrentScheme();
  }

  @Override
  public void setCurrentScheme(CodeStyleScheme scheme) {
    String schemeName = scheme == null ? null : scheme.getName();
    mySchemesManager.setCurrentSchemeName(schemeName);
    CURRENT_SCHEME_NAME = schemeName;
  }

  @SuppressWarnings("ForLoopThatDoesntUseLoopVariable")
  @Override
  public CodeStyleScheme createNewScheme(String preferredName, CodeStyleScheme parentScheme) {
    String name;
    if (preferredName == null) {
      if (parentScheme == null) throw new IllegalArgumentException("parentScheme must not be null");
      // Generate using parent name
      name = null;
      for (int i = 1; name == null; i++) {
        String currName = parentScheme.getName() + " (" + i + ")";
        if (findSchemeByName(currName) == null) {
          name = currName;
        }
      }
    }
    else {
      name = null;
      for (int i = 0; name == null; i++) {
        String currName = i == 0 ? preferredName : preferredName + " (" + i + ")";
        if (findSchemeByName(currName) == null) {
          name = currName;
        }
      }
    }
    return new CodeStyleSchemeImpl(name, false, parentScheme);
  }

  @Override
  public void deleteScheme(CodeStyleScheme scheme) {
    if (scheme.isDefault()) {
      throw new IllegalArgumentException("Unable to delete default scheme!");
    }
    CodeStyleSchemeImpl currScheme = (CodeStyleSchemeImpl)getCurrentScheme();
    if (currScheme == scheme) {
      CodeStyleScheme newCurrentScheme = getDefaultScheme();
      if (newCurrentScheme == null) {
        throw new IllegalStateException("Unable to load default scheme!");
      }
      setCurrentScheme(newCurrentScheme);
    }
    mySchemesManager.removeScheme(scheme);
  }

  @Override
  public CodeStyleScheme getDefaultScheme() {
    return findSchemeByName(DEFAULT_SCHEME_NAME);
  }

  @Nullable
  @Override
  public CodeStyleScheme findSchemeByName(@NotNull String name) {
    return mySchemesManager.findSchemeByName(name);
  }

  @Override
  public void addScheme(CodeStyleScheme scheme) {
    mySchemesManager.addNewScheme(scheme, true);
  }

  protected void init() {
    if (myIsInitialized) return;
    myIsInitialized = true;
    mySchemesManager.loadSchemes();
  }

  public SchemesManager<CodeStyleScheme, CodeStyleSchemeImpl> getSchemesManager() {
    return mySchemesManager;
  }
}


text:
CREATE USER 'dragonfly'@'localhost' IDENTIFIED BY 'dragonfly12345678';
GRANT ALL PRIVILEGES ON `test`.* TO 'dragonfly'@'localhost' WITH GRANT OPTION;
CREATE USER 'dragonfly'@'%' IDENTIFIED BY 'dragonfly12345678';
GRANT ALL PRIVILEGES ON `test`.* TO 'dragonfly'@'%' WITH GRANT OPTION;


text:
package org.htmlcleaner;

/**
 * Base class for all tokens. Allows position tracking.
 *
 * @author Konstantin Burov (aectann@gmail.com)
 *
 */
public abstract class BaseTokenImpl implements BaseToken {

    private int row;
    private int col;

    protected BaseTokenImpl(){

    }

    protected BaseTokenImpl(int row, int col) {
        this.row = row;
        this.col = col;
    }
    public int getRow() {
        return row;
    }
    public void setRow(int row) {
        this.row = row;
    }
    public int getCol() {
        return col;
    }
    public void setCol(int col) {
        this.col = col;
    }

    @Override
    public String toString() {
        return "(line="+getRow()+", col="+getCol()+")";
    }

}


text:
#include <config.h>

#include "jsonrpc-server.h"

#include <errno.h>

#include "bitmap.h"
#include "column.h"
#include "dynamic-string.h"
#include "json.h"
#include "jsonrpc.h"
#include "ovsdb-error.h"
#include "ovsdb-parser.h"
#include "ovsdb.h"
#include "poll-loop.h"
#include "reconnect.h"
#include "row.h"
#include "server.h"
#include "simap.h"
#include "stream.h"
#include "table.h"
#include "timeval.h"
#include "transaction.h"
#include "trigger.h"
#include "vlog.h"

VLOG_DEFINE_THIS_MODULE(ovsdb_jsonrpc_server);

struct ovsdb_jsonrpc_remote;
struct ovsdb_jsonrpc_session;

/* Message rate-limiting. */
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);

/* Sessions. */
static struct ovsdb_jsonrpc_session *ovsdb_jsonrpc_session_create(
    struct ovsdb_jsonrpc_remote *, struct jsonrpc_session *);
static void ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *);
static void ovsdb_jsonrpc_session_wait_all(struct ovsdb_jsonrpc_remote *);
static void ovsdb_jsonrpc_session_get_memory_usage_all(
    const struct ovsdb_jsonrpc_remote *, struct simap *usage);
static void ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *);
static void ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *);
static void ovsdb_jsonrpc_session_set_all_options(
    struct ovsdb_jsonrpc_remote *, const struct ovsdb_jsonrpc_options *);
static bool ovsdb_jsonrpc_session_get_status(
    const struct ovsdb_jsonrpc_remote *,
    struct ovsdb_jsonrpc_remote_status *);
static void ovsdb_jsonrpc_session_unlock_all(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_session_unlock__(struct ovsdb_lock_waiter *);
static void ovsdb_jsonrpc_session_send(struct ovsdb_jsonrpc_session *,
                                       struct jsonrpc_msg *);

/* Triggers. */
static void ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *,
                                         struct ovsdb *,
                                         struct json *id, struct json *params);
static struct ovsdb_jsonrpc_trigger *ovsdb_jsonrpc_trigger_find(
    struct ovsdb_jsonrpc_session *, const struct json *id, size_t hash);
static void ovsdb_jsonrpc_trigger_complete(struct ovsdb_jsonrpc_trigger *);
static void ovsdb_jsonrpc_trigger_complete_all(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_trigger_complete_done(
    struct ovsdb_jsonrpc_session *);

/* Monitors. */
static struct json *ovsdb_jsonrpc_monitor_create(
    struct ovsdb_jsonrpc_session *, struct ovsdb *, struct json *params);
static struct jsonrpc_msg *ovsdb_jsonrpc_monitor_cancel(
    struct ovsdb_jsonrpc_session *,
    struct json_array *params,
    const struct json *request_id);
static void ovsdb_jsonrpc_monitor_remove_all(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_monitor_flush_all(struct ovsdb_jsonrpc_session *);
static bool ovsdb_jsonrpc_monitor_needs_flush(struct ovsdb_jsonrpc_session *);

/* JSON-RPC database server. */

struct ovsdb_jsonrpc_server {
    struct ovsdb_server up;
    unsigned int n_sessions, max_sessions;
    struct shash remotes;      /* Contains "struct ovsdb_jsonrpc_remote *"s. */
};

/* A configured remote.  This is either a passive stream listener plus a list
 * of the currently connected sessions, or a list of exactly one active
 * session. */
struct ovsdb_jsonrpc_remote {
    struct ovsdb_jsonrpc_server *server;
    struct pstream *listener;   /* Listener, if passive. */
    struct list sessions;       /* List of "struct ovsdb_jsonrpc_session"s. */
    uint8_t dscp;
};

static struct ovsdb_jsonrpc_remote *ovsdb_jsonrpc_server_add_remote(
    struct ovsdb_jsonrpc_server *, const char *name,
    const struct ovsdb_jsonrpc_options *options
);
static void ovsdb_jsonrpc_server_del_remote(struct shash_node *);

/* Creates and returns a new server to provide JSON-RPC access to an OVSDB.
 *
 * The caller must call ovsdb_jsonrpc_server_add_db() for each database to
 * which 'server' should provide access. */
struct ovsdb_jsonrpc_server *
ovsdb_jsonrpc_server_create(void)
{
    struct ovsdb_jsonrpc_server *server = xzalloc(sizeof *server);
    ovsdb_server_init(&server->up);
    server->max_sessions = 64;
    shash_init(&server->remotes);
    return server;
}

/* Adds 'db' to the set of databases served out by 'svr'.  Returns true if
 * successful, false if 'db''s name is the same as some database already in
 * 'server'. */
bool
ovsdb_jsonrpc_server_add_db(struct ovsdb_jsonrpc_server *svr, struct ovsdb *db)
{
    /* The OVSDB protocol doesn't have a way to notify a client that a
     * database has been added.  If some client tried to use the database
     * that we're adding and failed, then forcing it to reconnect seems like
     * a reasonable way to make it try again.
     *
     * If this is too big of a hammer in practice, we could be more selective,
     * e.g. disconnect only connections that actually tried to use a database
     * with 'db''s name. */
    ovsdb_jsonrpc_server_reconnect(svr);

    return ovsdb_server_add_db(&svr->up, db);
}

/* Removes 'db' from the set of databases served out by 'svr'.  Returns
 * true if successful, false if there is no database associated with 'db'. */
bool
ovsdb_jsonrpc_server_remove_db(struct ovsdb_jsonrpc_server *svr,
                               struct ovsdb *db)
{
    /* There might be pointers to 'db' from 'svr', such as monitors or
     * outstanding transactions.  Disconnect all JSON-RPC connections to avoid
     * accesses to freed memory.
     *
     * If this is too big of a hammer in practice, we could be more selective,
     * e.g. disconnect only connections that actually reference 'db'. */
    ovsdb_jsonrpc_server_reconnect(svr);

    return ovsdb_server_remove_db(&svr->up, db);
}

void
ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr)
{
    struct shash_node *node, *next;

    SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
        ovsdb_jsonrpc_server_del_remote(node);
    }
    shash_destroy(&svr->remotes);
    ovsdb_server_destroy(&svr->up);
    free(svr);
}

struct ovsdb_jsonrpc_options *
ovsdb_jsonrpc_default_options(const char *target)
{
    struct ovsdb_jsonrpc_options *options = xzalloc(sizeof *options);
    options->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
    options->probe_interval = (stream_or_pstream_needs_probes(target)
                               ? RECONNECT_DEFAULT_PROBE_INTERVAL
                               : 0);
    return options;
}

/* Sets 'svr''s current set of remotes to the names in 'new_remotes', with
 * options in the struct ovsdb_jsonrpc_options supplied as the data values.
 *
 * A remote is an active or passive stream connection method, e.g. "pssl:" or
 * "tcp:1.2.3.4". */
void
ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *svr,
                                 const struct shash *new_remotes)
{
    struct shash_node *node, *next;

    SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
        if (!shash_find(new_remotes, node->name)) {
            VLOG_INFO("%s: remote deconfigured", node->name);
            ovsdb_jsonrpc_server_del_remote(node);
        }
    }
    SHASH_FOR_EACH (node, new_remotes) {
        const struct ovsdb_jsonrpc_options *options = node->data;
        struct ovsdb_jsonrpc_remote *remote;

        remote = shash_find_data(&svr->remotes, node->name);
        if (!remote) {
            remote = ovsdb_jsonrpc_server_add_remote(svr, node->name, options);
            if (!remote) {
                continue;
            }
        }

        ovsdb_jsonrpc_session_set_all_options(remote, options);
    }
}

static struct ovsdb_jsonrpc_remote *
ovsdb_jsonrpc_server_add_remote(struct ovsdb_jsonrpc_server *svr,
                                const char *name,
                                const struct ovsdb_jsonrpc_options *options)
{
    struct ovsdb_jsonrpc_remote *remote;
    struct pstream *listener;
    int error;

    error = jsonrpc_pstream_open(name, &listener, options->dscp);
    if (error && error != EAFNOSUPPORT) {
        VLOG_ERR_RL(&rl, "%s: listen failed: %s", name, ovs_strerror(error));
        return NULL;
    }

    remote = xmalloc(sizeof *remote);
    remote->server = svr;
    remote->listener = listener;
    list_init(&remote->sessions);
    remote->dscp = options->dscp;
    shash_add(&svr->remotes, name, remote);

    if (!listener) {
        ovsdb_jsonrpc_session_create(remote, jsonrpc_session_open(name, true));
    }
    return remote;
}

static void
ovsdb_jsonrpc_server_del_remote(struct shash_node *node)
{
    struct ovsdb_jsonrpc_remote *remote = node->data;

    ovsdb_jsonrpc_session_close_all(remote);
    pstream_close(remote->listener);
    shash_delete(&remote->server->remotes, node);
    free(remote);
}

/* Stores status information for the remote named 'target', which should have
 * been configured on 'svr' with a call to ovsdb_jsonrpc_server_set_remotes(),
 * into '*status'.  On success returns true, on failure (if 'svr' doesn't have
 * a remote named 'target' or if that remote is an inbound remote that has no
 * active connections) returns false.  On failure, 'status' will be zeroed.
 */
bool
ovsdb_jsonrpc_server_get_remote_status(
    const struct ovsdb_jsonrpc_server *svr, const char *target,
    struct ovsdb_jsonrpc_remote_status *status)
{
    const struct ovsdb_jsonrpc_remote *remote;

    memset(status, 0, sizeof *status);

    remote = shash_find_data(&svr->remotes, target);
    return remote && ovsdb_jsonrpc_session_get_status(remote, status);
}

void
ovsdb_jsonrpc_server_free_remote_status(
    struct ovsdb_jsonrpc_remote_status *status)
{
    free(status->locks_held);
    free(status->locks_waiting);
    free(status->locks_lost);
}

/* Forces all of the JSON-RPC sessions managed by 'svr' to disconnect and
 * reconnect. */
void
ovsdb_jsonrpc_server_reconnect(struct ovsdb_jsonrpc_server *svr)
{
    struct shash_node *node;

    SHASH_FOR_EACH (node, &svr->remotes) {
        struct ovsdb_jsonrpc_remote *remote = node->data;

        ovsdb_jsonrpc_session_reconnect_all(remote);
    }
}

void
ovsdb_jsonrpc_server_run(struct ovsdb_jsonrpc_server *svr)
{
    struct shash_node *node;

    SHASH_FOR_EACH (node, &svr->remotes) {
        struct ovsdb_jsonrpc_remote *remote = node->data;

        if (remote->listener && svr->n_sessions < svr->max_sessions) {
            struct stream *stream;
            int error;

            error = pstream_accept(remote->listener, &stream);
            if (!error) {
                struct jsonrpc_session *js;
                js = jsonrpc_session_open_unreliably(jsonrpc_open(stream),
                                                     remote->dscp);
                ovsdb_jsonrpc_session_create(remote, js);
            } else if (error != EAGAIN) {
                VLOG_WARN_RL(&rl, "%s: accept failed: %s",
                             pstream_get_name(remote->listener),
                             ovs_strerror(error));
            }
        }

        ovsdb_jsonrpc_session_run_all(remote);
    }
}

void
ovsdb_jsonrpc_server_wait(struct ovsdb_jsonrpc_server *svr)
{
    struct shash_node *node;

    SHASH_FOR_EACH (node, &svr->remotes) {
        struct ovsdb_jsonrpc_remote *remote = node->data;

        if (remote->listener && svr->n_sessions < svr->max_sessions) {
            pstream_wait(remote->listener);
        }

        ovsdb_jsonrpc_session_wait_all(remote);
    }
}

/* Adds some memory usage statistics for 'svr' into 'usage', for use with
 * memory_report(). */
void
ovsdb_jsonrpc_server_get_memory_usage(const struct ovsdb_jsonrpc_server *svr,
                                      struct simap *usage)
{
    struct shash_node *node;

    simap_increase(usage, "sessions", svr->n_sessions);
    SHASH_FOR_EACH (node, &svr->remotes) {
        struct ovsdb_jsonrpc_remote *remote = node->data;

        ovsdb_jsonrpc_session_get_memory_usage_all(remote, usage);
    }
}

/* JSON-RPC database server session. */

struct ovsdb_jsonrpc_session {
    struct list node;           /* Element in remote's sessions list. */
    struct ovsdb_session up;
    struct ovsdb_jsonrpc_remote *remote;

    /* Triggers. */
    struct hmap triggers;       /* Hmap of "struct ovsdb_jsonrpc_trigger"s. */

    /* Monitors. */
    struct hmap monitors;       /* Hmap of "struct ovsdb_jsonrpc_monitor"s. */

    /* Network connectivity. */
    struct jsonrpc_session *js;  /* JSON-RPC session. */
    unsigned int js_seqno;       /* Last jsonrpc_session_get_seqno() value. */
};

static void ovsdb_jsonrpc_session_close(struct ovsdb_jsonrpc_session *);
static int ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_session_wait(struct ovsdb_jsonrpc_session *);
static void ovsdb_jsonrpc_session_get_memory_usage(
    const struct ovsdb_jsonrpc_session *, struct simap *usage);
static void ovsdb_jsonrpc_session_set_options(
    struct ovsdb_jsonrpc_session *, const struct ovsdb_jsonrpc_options *);
static void ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *,
                                             struct jsonrpc_msg *);
static void ovsdb_jsonrpc_session_got_notify(struct ovsdb_jsonrpc_session *,
                                             struct jsonrpc_msg *);

static struct ovsdb_jsonrpc_session *
ovsdb_jsonrpc_session_create(struct ovsdb_jsonrpc_remote *remote,
                             struct jsonrpc_session *js)
{
    struct ovsdb_jsonrpc_session *s;

    s = xzalloc(sizeof *s);
    ovsdb_session_init(&s->up, &remote->server->up);
    s->remote = remote;
    list_push_back(&remote->sessions, &s->node);
    hmap_init(&s->triggers);
    hmap_init(&s->monitors);
    s->js = js;
    s->js_seqno = jsonrpc_session_get_seqno(js);

    remote->server->n_sessions++;

    return s;
}

static void
ovsdb_jsonrpc_session_close(struct ovsdb_jsonrpc_session *s)
{
    ovsdb_jsonrpc_monitor_remove_all(s);
    ovsdb_jsonrpc_session_unlock_all(s);
    ovsdb_jsonrpc_trigger_complete_all(s);

    hmap_destroy(&s->monitors);
    hmap_destroy(&s->triggers);

    jsonrpc_session_close(s->js);
    list_remove(&s->node);
    s->remote->server->n_sessions--;
    ovsdb_session_destroy(&s->up);
    free(s);
}

static int
ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *s)
{
    jsonrpc_session_run(s->js);
    if (s->js_seqno != jsonrpc_session_get_seqno(s->js)) {
        s->js_seqno = jsonrpc_session_get_seqno(s->js);
        ovsdb_jsonrpc_trigger_complete_all(s);
        ovsdb_jsonrpc_monitor_remove_all(s);
        ovsdb_jsonrpc_session_unlock_all(s);
    }

    ovsdb_jsonrpc_trigger_complete_done(s);

    if (!jsonrpc_session_get_backlog(s->js)) {
        struct jsonrpc_msg *msg;

        ovsdb_jsonrpc_monitor_flush_all(s);

        msg = jsonrpc_session_recv(s->js);
        if (msg) {
            if (msg->type == JSONRPC_REQUEST) {
                ovsdb_jsonrpc_session_got_request(s, msg);
            } else if (msg->type == JSONRPC_NOTIFY) {
                ovsdb_jsonrpc_session_got_notify(s, msg);
            } else {
                VLOG_WARN("%s: received unexpected %s message",
                          jsonrpc_session_get_name(s->js),
                          jsonrpc_msg_type_to_string(msg->type));
                jsonrpc_session_force_reconnect(s->js);
                jsonrpc_msg_destroy(msg);
            }
        }
    }
    return jsonrpc_session_is_alive(s->js) ? 0 : ETIMEDOUT;
}

static void
ovsdb_jsonrpc_session_set_options(struct ovsdb_jsonrpc_session *session,
                                  const struct ovsdb_jsonrpc_options *options)
{
    jsonrpc_session_set_max_backoff(session->js, options->max_backoff);
    jsonrpc_session_set_probe_interval(session->js, options->probe_interval);
    jsonrpc_session_set_dscp(session->js, options->dscp);
}

static void
ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *remote)
{
    struct ovsdb_jsonrpc_session *s, *next;

    LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) {
        int error = ovsdb_jsonrpc_session_run(s);
        if (error) {
            ovsdb_jsonrpc_session_close(s);
        }
    }
}

static void
ovsdb_jsonrpc_session_wait(struct ovsdb_jsonrpc_session *s)
{
    jsonrpc_session_wait(s->js);
    if (!jsonrpc_session_get_backlog(s->js)) {
        if (ovsdb_jsonrpc_monitor_needs_flush(s)) {
            poll_immediate_wake();
        } else {
            jsonrpc_session_recv_wait(s->js);
        }
    }
}

static void
ovsdb_jsonrpc_session_wait_all(struct ovsdb_jsonrpc_remote *remote)
{
    struct ovsdb_jsonrpc_session *s;

    LIST_FOR_EACH (s, node, &remote->sessions) {
        ovsdb_jsonrpc_session_wait(s);
    }
}

static void
ovsdb_jsonrpc_session_get_memory_usage(const struct ovsdb_jsonrpc_session *s,
                                       struct simap *usage)
{
    simap_increase(usage, "triggers", hmap_count(&s->triggers));
    simap_increase(usage, "monitors", hmap_count(&s->monitors));
    simap_increase(usage, "backlog", jsonrpc_session_get_backlog(s->js));
}

static void
ovsdb_jsonrpc_session_get_memory_usage_all(
    const struct ovsdb_jsonrpc_remote *remote,
    struct simap *usage)
{
    struct ovsdb_jsonrpc_session *s;

    LIST_FOR_EACH (s, node, &remote->sessions) {
        ovsdb_jsonrpc_session_get_memory_usage(s, usage);
    }
}

static void
ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *remote)
{
    struct ovsdb_jsonrpc_session *s, *next;

    LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) {
        ovsdb_jsonrpc_session_close(s);
    }
}

/* Forces all of the JSON-RPC sessions managed by 'remote' to disconnect and
 * reconnect. */
static void
ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *remote)
{
    struct ovsdb_jsonrpc_session *s, *next;

    LIST_FOR_EACH_SAFE (s, next, node, &remote->sessions) {
        jsonrpc_session_force_reconnect(s->js);
        if (!jsonrpc_session_is_alive(s->js)) {
            ovsdb_jsonrpc_session_close(s);
        }
    }
}

/* Sets the options for all of the JSON-RPC sessions managed by 'remote' to
 * 'options'. */
static void
ovsdb_jsonrpc_session_set_all_options(
    struct ovsdb_jsonrpc_remote *remote,
    const struct ovsdb_jsonrpc_options *options)
{
    struct ovsdb_jsonrpc_session *s;

    if (remote->listener) {
        int error;

        error = pstream_set_dscp(remote->listener, options->dscp);
        if (error) {
            VLOG_ERR("%s: set_dscp failed %s",
                     pstream_get_name(remote->listener), ovs_strerror(error));
        } else {
            remote->dscp = options->dscp;
        }
        /*
         * XXX race window between setting dscp to listening socket
         * and accepting socket. Accepted socket may have old dscp value.
         * Ignore this race window for now.
         */
    }
    LIST_FOR_EACH (s, node, &remote->sessions) {
        ovsdb_jsonrpc_session_set_options(s, options);
    }
}

static bool
ovsdb_jsonrpc_session_get_status(const struct ovsdb_jsonrpc_remote *remote,
                                 struct ovsdb_jsonrpc_remote_status *status)
{
    const struct ovsdb_jsonrpc_session *s;
    const struct jsonrpc_session *js;
    struct ovsdb_lock_waiter *waiter;
    struct reconnect_stats rstats;
    struct ds locks_held, locks_waiting, locks_lost;

    status->bound_port = (remote->listener
                          ? pstream_get_bound_port(remote->listener)
                          : htons(0));

    if (list_is_empty(&remote->sessions)) {
        return false;
    }
    s = CONTAINER_OF(remote->sessions.next, struct ovsdb_jsonrpc_session, node);
    js = s->js;

    status->is_connected = jsonrpc_session_is_connected(js);
    status->last_error = jsonrpc_session_get_status(js);

    jsonrpc_session_get_reconnect_stats(js, &rstats);
    status->state = rstats.state;
    status->sec_since_connect = rstats.msec_since_connect == UINT_MAX
        ? UINT_MAX : rstats.msec_since_connect / 1000;
    status->sec_since_disconnect = rstats.msec_since_disconnect == UINT_MAX
        ? UINT_MAX : rstats.msec_since_disconnect / 1000;

    ds_init(&locks_held);
    ds_init(&locks_waiting);
    ds_init(&locks_lost);
    HMAP_FOR_EACH (waiter, session_node, &s->up.waiters) {
        struct ds *string;

        string = (ovsdb_lock_waiter_is_owner(waiter) ? &locks_held
                  : waiter->mode == OVSDB_LOCK_WAIT ? &locks_waiting
                  : &locks_lost);
        if (string->length) {
            ds_put_char(string, ' ');
        }
        ds_put_cstr(string, waiter->lock_name);
    }
    status->locks_held = ds_steal_cstr(&locks_held);
    status->locks_waiting = ds_steal_cstr(&locks_waiting);
    status->locks_lost = ds_steal_cstr(&locks_lost);

    status->n_connections = list_size(&remote->sessions);

    return true;
}

/* Examines 'request' to determine the database to which it relates, and then
 * searches 's' to find that database:
 *
 *    - If successful, returns the database and sets '*replyp' to NULL.
 *
 *    - If no such database exists, returns NULL and sets '*replyp' to an
 *      appropriate JSON-RPC error reply, owned by the caller. */
static struct ovsdb *
ovsdb_jsonrpc_lookup_db(const struct ovsdb_jsonrpc_session *s,
                        const struct jsonrpc_msg *request,
                        struct jsonrpc_msg **replyp)
{
    struct json_array *params;
    struct ovsdb_error *error;
    const char *db_name;
    struct ovsdb *db;

    params = json_array(request->params);
    if (!params->n || params->elems[0]->type != JSON_STRING) {
        error = ovsdb_syntax_error(
            request->params, NULL,
            "%s request params must begin with <db-name>", request->method);
        goto error;
    }

    db_name = params->elems[0]->u.string;
    db = shash_find_data(&s->up.server->dbs, db_name);
    if (!db) {
        error = ovsdb_syntax_error(
            request->params, "unknown database",
            "%s request specifies unknown database %s",
            request->method, db_name);
        goto error;
    }

    *replyp = NULL;
    return db;

error:
    *replyp = jsonrpc_create_reply(ovsdb_error_to_json(error), request->id);
    ovsdb_error_destroy(error);
    return NULL;
}

static struct ovsdb_error *
ovsdb_jsonrpc_session_parse_lock_name(const struct jsonrpc_msg *request,
                                      const char **lock_namep)
{
    const struct json_array *params;

    params = json_array(request->params);
    if (params->n != 1 || params->elems[0]->type != JSON_STRING ||
        !ovsdb_parser_is_id(json_string(params->elems[0]))) {
        *lock_namep = NULL;
        return ovsdb_syntax_error(request->params, NULL,
                                  "%s request params must be <id>",
                                  request->method);
    }

    *lock_namep = json_string(params->elems[0]);
    return NULL;
}

static void
ovsdb_jsonrpc_session_notify(struct ovsdb_session *session,
                             const char *lock_name,
                             const char *method)
{
    struct ovsdb_jsonrpc_session *s;
    struct json *params;

    s = CONTAINER_OF(session, struct ovsdb_jsonrpc_session, up);
    params = json_array_create_1(json_string_create(lock_name));
    ovsdb_jsonrpc_session_send(s, jsonrpc_create_notify(method, params));
}

static struct jsonrpc_msg *
ovsdb_jsonrpc_session_lock(struct ovsdb_jsonrpc_session *s,
                           struct jsonrpc_msg *request,
                           enum ovsdb_lock_mode mode)
{
    struct ovsdb_lock_waiter *waiter;
    struct jsonrpc_msg *reply;
    struct ovsdb_error *error;
    struct ovsdb_session *victim;
    const char *lock_name;
    struct json *result;

    error = ovsdb_jsonrpc_session_parse_lock_name(request, &lock_name);
    if (error) {
        goto error;
    }

    /* Report error if this session has issued a "lock" or "steal" without a
     * matching "unlock" for this lock. */
    waiter = ovsdb_session_get_lock_waiter(&s->up, lock_name);
    if (waiter) {
        error = ovsdb_syntax_error(
            request->params, NULL,
            "must issue \"unlock\" before new \"%s\"", request->method);
        goto error;
    }

    /* Get the lock, add us as a waiter. */
    waiter = ovsdb_server_lock(&s->remote->server->up, &s->up, lock_name, mode,
                               &victim);
    if (victim) {
        ovsdb_jsonrpc_session_notify(victim, lock_name, "stolen");
    }

    result = json_object_create();
    json_object_put(result, "locked",
                    json_boolean_create(ovsdb_lock_waiter_is_owner(waiter)));

    return jsonrpc_create_reply(result, request->id);

error:
    reply = jsonrpc_create_reply(ovsdb_error_to_json(error), request->id);
    ovsdb_error_destroy(error);
    return reply;
}

static void
ovsdb_jsonrpc_session_unlock_all(struct ovsdb_jsonrpc_session *s)
{
    struct ovsdb_lock_waiter *waiter, *next;

    HMAP_FOR_EACH_SAFE (waiter, next, session_node, &s->up.waiters) {
        ovsdb_jsonrpc_session_unlock__(waiter);
    }
}

static void
ovsdb_jsonrpc_session_unlock__(struct ovsdb_lock_waiter *waiter)
{
    struct ovsdb_lock *lock = waiter->lock;

    if (lock) {
        struct ovsdb_session *new_owner = ovsdb_lock_waiter_remove(waiter);
        if (new_owner) {
            ovsdb_jsonrpc_session_notify(new_owner, lock->name, "locked");
        } else {
            /* ovsdb_server_lock() might have freed 'lock'. */
        }
    }

    ovsdb_lock_waiter_destroy(waiter);
}

static struct jsonrpc_msg *
ovsdb_jsonrpc_session_unlock(struct ovsdb_jsonrpc_session *s,
                             struct jsonrpc_msg *request)
{
    struct ovsdb_lock_waiter *waiter;
    struct jsonrpc_msg *reply;
    struct ovsdb_error *error;
    const char *lock_name;

    error = ovsdb_jsonrpc_session_parse_lock_name(request, &lock_name);
    if (error) {
        goto error;
    }

    /* Report error if this session has not issued a "lock" or "steal" for this
     * lock. */
    waiter = ovsdb_session_get_lock_waiter(&s->up, lock_name);
    if (!waiter) {
        error = ovsdb_syntax_error(
            request->params, NULL, "\"unlock\" without \"lock\" or \"steal\"");
        goto error;
    }

    ovsdb_jsonrpc_session_unlock__(waiter);

    return jsonrpc_create_reply(json_object_create(), request->id);

error:
    reply = jsonrpc_create_reply(ovsdb_error_to_json(error), request->id);
    ovsdb_error_destroy(error);
    return reply;
}

static struct jsonrpc_msg *
execute_transaction(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
                    struct jsonrpc_msg *request)
{
    ovsdb_jsonrpc_trigger_create(s, db, request->id, request->params);
    request->id = NULL;
    request->params = NULL;
    jsonrpc_msg_destroy(request);
    return NULL;
}

static void
ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *s,
                                  struct jsonrpc_msg *request)
{
    struct jsonrpc_msg *reply;

    if (!strcmp(request->method, "transact")) {
        struct ovsdb *db = ovsdb_jsonrpc_lookup_db(s, request, &reply);
        if (!reply) {
            reply = execute_transaction(s, db, request);
        }
    } else if (!strcmp(request->method, "monitor")) {
        struct ovsdb *db = ovsdb_jsonrpc_lookup_db(s, request, &reply);
        if (!reply) {
            reply = jsonrpc_create_reply(
                ovsdb_jsonrpc_monitor_create(s, db, request->params),
                request->id);
        }
    } else if (!strcmp(request->method, "monitor_cancel")) {
        reply = ovsdb_jsonrpc_monitor_cancel(s, json_array(request->params),
                                             request->id);
    } else if (!strcmp(request->method, "get_schema")) {
        struct ovsdb *db = ovsdb_jsonrpc_lookup_db(s, request, &reply);
        if (!reply) {
            reply = jsonrpc_create_reply(ovsdb_schema_to_json(db->schema),
                                         request->id);
        }
    } else if (!strcmp(request->method, "list_dbs")) {
        size_t n_dbs = shash_count(&s->up.server->dbs);
        struct shash_node *node;
        struct json **dbs;
        size_t i;

        dbs = xmalloc(n_dbs * sizeof *dbs);
        i = 0;
        SHASH_FOR_EACH (node, &s->up.server->dbs) {
            dbs[i++] = json_string_create(node->name);
        }
        reply = jsonrpc_create_reply(json_array_create(dbs, n_dbs),
                                     request->id);
    } else if (!strcmp(request->method, "lock")) {
        reply = ovsdb_jsonrpc_session_lock(s, request, OVSDB_LOCK_WAIT);
    } else if (!strcmp(request->method, "steal")) {
        reply = ovsdb_jsonrpc_session_lock(s, request, OVSDB_LOCK_STEAL);
    } else if (!strcmp(request->method, "unlock")) {
        reply = ovsdb_jsonrpc_session_unlock(s, request);
    } else if (!strcmp(request->method, "echo")) {
        reply = jsonrpc_create_reply(json_clone(request->params), request->id);
    } else {
        reply = jsonrpc_create_error(json_string_create("unknown method"),
                                     request->id);
    }

    if (reply) {
        jsonrpc_msg_destroy(request);
        ovsdb_jsonrpc_session_send(s, reply);
    }
}

static void
execute_cancel(struct ovsdb_jsonrpc_session *s, struct jsonrpc_msg *request)
{
    if (json_array(request->params)->n == 1) {
        struct ovsdb_jsonrpc_trigger *t;
        struct json *id;

        id = request->params->u.array.elems[0];
        t = ovsdb_jsonrpc_trigger_find(s, id, json_hash(id, 0));
        if (t) {
            ovsdb_jsonrpc_trigger_complete(t);
        }
    }
}

static void
ovsdb_jsonrpc_session_got_notify(struct ovsdb_jsonrpc_session *s,
                                 struct jsonrpc_msg *request)
{
    if (!strcmp(request->method, "cancel")) {
        execute_cancel(s, request);
    }
    jsonrpc_msg_destroy(request);
}

static void
ovsdb_jsonrpc_session_send(struct ovsdb_jsonrpc_session *s,
                           struct jsonrpc_msg *msg)
{
    ovsdb_jsonrpc_monitor_flush_all(s);
    jsonrpc_session_send(s->js, msg);
}

/* JSON-RPC database server triggers.
 *
 * (Every transaction is treated as a trigger even if it doesn't actually have
 * any "wait" operations.) */

struct ovsdb_jsonrpc_trigger {
    struct ovsdb_trigger trigger;
    struct hmap_node hmap_node; /* In session's "triggers" hmap. */
    struct json *id;
};

static void
ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
                             struct json *id, struct json *params)
{
    struct ovsdb_jsonrpc_trigger *t;
    size_t hash;

    /* Check for duplicate ID. */
    hash = json_hash(id, 0);
    t = ovsdb_jsonrpc_trigger_find(s, id, hash);
    if (t) {
        struct jsonrpc_msg *msg;

        msg = jsonrpc_create_error(json_string_create("duplicate request ID"),
                                   id);
        ovsdb_jsonrpc_session_send(s, msg);
        json_destroy(id);
        json_destroy(params);
        return;
    }

    /* Insert into trigger table. */
    t = xmalloc(sizeof *t);
    ovsdb_trigger_init(&s->up, db, &t->trigger, params, time_msec());
    t->id = id;
    hmap_insert(&s->triggers, &t->hmap_node, hash);

    /* Complete early if possible. */
    if (ovsdb_trigger_is_complete(&t->trigger)) {
        ovsdb_jsonrpc_trigger_complete(t);
    }
}

static struct ovsdb_jsonrpc_trigger *
ovsdb_jsonrpc_trigger_find(struct ovsdb_jsonrpc_session *s,
                           const struct json *id, size_t hash)
{
    struct ovsdb_jsonrpc_trigger *t;

    HMAP_FOR_EACH_WITH_HASH (t, hmap_node, hash, &s->triggers) {
        if (json_equal(t->id, id)) {
            return t;
        }
    }

    return NULL;
}

static void
ovsdb_jsonrpc_trigger_complete(struct ovsdb_jsonrpc_trigger *t)
{
    struct ovsdb_jsonrpc_session *s;

    s = CONTAINER_OF(t->trigger.session, struct ovsdb_jsonrpc_session, up);

    if (jsonrpc_session_is_connected(s->js)) {
        struct jsonrpc_msg *reply;
        struct json *result;

        result = ovsdb_trigger_steal_result(&t->trigger);
        if (result) {
            reply = jsonrpc_create_reply(result, t->id);
        } else {
            reply = jsonrpc_create_error(json_string_create("canceled"),
                                         t->id);
        }
        ovsdb_jsonrpc_session_send(s, reply);
    }

    json_destroy(t->id);
    ovsdb_trigger_destroy(&t->trigger);
    hmap_remove(&s->triggers, &t->hmap_node);
    free(t);
}

static void
ovsdb_jsonrpc_trigger_complete_all(struct ovsdb_jsonrpc_session *s)
{
    struct ovsdb_jsonrpc_trigger *t, *next;
    HMAP_FOR_EACH_SAFE (t, next, hmap_node, &s->triggers) {
        ovsdb_jsonrpc_trigger_complete(t);
    }
}

static void
ovsdb_jsonrpc_trigger_complete_done(struct ovsdb_jsonrpc_session *s)
{
    while (!list_is_empty(&s->up.completions)) {
        struct ovsdb_jsonrpc_trigger *t
            = CONTAINER_OF(s->up.completions.next,
                           struct ovsdb_jsonrpc_trigger, trigger.node);
        ovsdb_jsonrpc_trigger_complete(t);
    }
}

/* JSON-RPC database table monitors. */

enum ovsdb_jsonrpc_monitor_selection {
    OJMS_INITIAL = 1 << 0,      /* All rows when monitor is created. */
    OJMS_INSERT = 1 << 1,       /* New rows. */
    OJMS_DELETE = 1 << 2,       /* Deleted rows. */
    OJMS_MODIFY = 1 << 3        /* Modified rows. */
};

/* A particular column being monitored. */
struct ovsdb_jsonrpc_monitor_column {
    const struct ovsdb_column *column;
    enum ovsdb_jsonrpc_monitor_selection select;
};

/* A row that has changed in a monitored table. */
struct ovsdb_jsonrpc_monitor_row {
    struct hmap_node hmap_node; /* In ovsdb_jsonrpc_monitor_table.changes. */
    struct uuid uuid;           /* UUID of row that changed. */
    struct ovsdb_datum *old;    /* Old data, NULL for an inserted row. */
    struct ovsdb_datum *new;    /* New data, NULL for a deleted row. */
};

/* A particular table being monitored. */
struct ovsdb_jsonrpc_monitor_table {
    const struct ovsdb_table *table;

    /* This is the union (bitwise-OR) of the 'select' values in all of the
     * members of 'columns' below. */
    enum ovsdb_jsonrpc_monitor_selection select;

    /* Columns being monitored. */
    struct ovsdb_jsonrpc_monitor_column *columns;
    size_t n_columns;

    /* Contains 'struct ovsdb_jsonrpc_monitor_row's for rows that have been
     * updated but not yet flushed to the jsonrpc connection. */
    struct hmap changes;
};

/* A collection of tables being monitored. */
struct ovsdb_jsonrpc_monitor {
    struct ovsdb_replica replica;
    struct ovsdb_jsonrpc_session *session;
    struct ovsdb *db;
    struct hmap_node node;      /* In ovsdb_jsonrpc_session's "monitors". */

    struct json *monitor_id;
    struct shash tables;     /* Holds "struct ovsdb_jsonrpc_monitor_table"s. */
};

static const struct ovsdb_replica_class ovsdb_jsonrpc_replica_class;

struct ovsdb_jsonrpc_monitor *ovsdb_jsonrpc_monitor_find(
    struct ovsdb_jsonrpc_session *, const struct json *monitor_id);
static void ovsdb_jsonrpc_monitor_destroy(struct ovsdb_replica *);
static struct json *ovsdb_jsonrpc_monitor_get_initial(
    const struct ovsdb_jsonrpc_monitor *);

static bool
parse_bool(struct ovsdb_parser *parser, const char *name, bool default_value)
{
    const struct json *json;

    json = ovsdb_parser_member(parser, name, OP_BOOLEAN | OP_OPTIONAL);
    return json ? json_boolean(json) : default_value;
}

struct ovsdb_jsonrpc_monitor *
ovsdb_jsonrpc_monitor_find(struct ovsdb_jsonrpc_session *s,
                           const struct json *monitor_id)
{
    struct ovsdb_jsonrpc_monitor *m;

    HMAP_FOR_EACH_WITH_HASH (m, node, json_hash(monitor_id, 0), &s->monitors) {
        if (json_equal(m->monitor_id, monitor_id)) {
            return m;
        }
    }

    return NULL;
}

static void
ovsdb_jsonrpc_add_monitor_column(struct ovsdb_jsonrpc_monitor_table *mt,
                                 const struct ovsdb_column *column,
                                 enum ovsdb_jsonrpc_monitor_selection select,
                                 size_t *allocated_columns)
{
    struct ovsdb_jsonrpc_monitor_column *c;

    if (mt->n_columns >= *allocated_columns) {
        mt->columns = x2nrealloc(mt->columns, allocated_columns,
                                 sizeof *mt->columns);
    }

    c = &mt->columns[mt->n_columns++];
    c->column = column;
    c->select = select;
}

static int
compare_ovsdb_jsonrpc_monitor_column(const void *a_, const void *b_)
{
    const struct ovsdb_jsonrpc_monitor_column *a = a_;
    const struct ovsdb_jsonrpc_monitor_column *b = b_;

    return a->column < b->column ? -1 : a->column > b->column;
}

static struct ovsdb_error * WARN_UNUSED_RESULT
ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_jsonrpc_monitor_table *mt,
                                    const struct json *monitor_request,
                                    size_t *allocated_columns)
{
    const struct ovsdb_table_schema *ts = mt->table->schema;
    enum ovsdb_jsonrpc_monitor_selection select;
    const struct json *columns, *select_json;
    struct ovsdb_parser parser;
    struct ovsdb_error *error;

    ovsdb_parser_init(&parser, monitor_request, "table %s", ts->name);
    columns = ovsdb_parser_member(&parser, "columns", OP_ARRAY | OP_OPTIONAL);
    select_json = ovsdb_parser_member(&parser, "select",
                                      OP_OBJECT | OP_OPTIONAL);
    error = ovsdb_parser_finish(&parser);
    if (error) {
        return error;
    }

    if (select_json) {
        select = 0;
        ovsdb_parser_init(&parser, select_json, "table %s select", ts->name);
        if (parse_bool(&parser, "initial", true)) {
            select |= OJMS_INITIAL;
        }
        if (parse_bool(&parser, "insert", true)) {
            select |= OJMS_INSERT;
        }
        if (parse_bool(&parser, "delete", true)) {
            select |= OJMS_DELETE;
        }
        if (parse_bool(&parser, "modify", true)) {
            select |= OJMS_MODIFY;
        }
        error = ovsdb_parser_finish(&parser);
        if (error) {
            return error;
        }
    } else {
        select = OJMS_INITIAL | OJMS_INSERT | OJMS_DELETE | OJMS_MODIFY;
    }
    mt->select |= select;

    if (columns) {
        size_t i;

        if (columns->type != JSON_ARRAY) {
            return ovsdb_syntax_error(columns, NULL,
                                      "array of column names expected");
        }

        for (i = 0; i < columns->u.array.n; i++) {
            const struct ovsdb_column *column;
            const char *s;

            if (columns->u.array.elems[i]->type != JSON_STRING) {
                return ovsdb_syntax_error(columns, NULL,
                                          "array of column names expected");
            }

            s = columns->u.array.elems[i]->u.string;
            column = shash_find_data(&mt->table->schema->columns, s);
            if (!column) {
                return ovsdb_syntax_error(columns, NULL, "%s is not a valid "
                                          "column name", s);
            }
            ovsdb_jsonrpc_add_monitor_column(mt, column, select,
                                             allocated_columns);
        }
    } else {
        struct shash_node *node;

        SHASH_FOR_EACH (node, &ts->columns) {
            const struct ovsdb_column *column = node->data;
            if (column->index != OVSDB_COL_UUID) {
                ovsdb_jsonrpc_add_monitor_column(mt, column, select,
                                                 allocated_columns);
            }
        }
    }

    return NULL;
}

static struct json *
ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
                             struct json *params)
{
    struct ovsdb_jsonrpc_monitor *m = NULL;
    struct json *monitor_id, *monitor_requests;
    struct ovsdb_error *error = NULL;
    struct shash_node *node;
    struct json *json;

    if (json_array(params)->n != 3) {
        error = ovsdb_syntax_error(params, NULL, "invalid parameters");
        goto error;
    }
    monitor_id = params->u.array.elems[1];
    monitor_requests = params->u.array.elems[2];
    if (monitor_requests->type != JSON_OBJECT) {
        error = ovsdb_syntax_error(monitor_requests, NULL,
                                   "monitor-requests must be object");
        goto error;
    }

    if (ovsdb_jsonrpc_monitor_find(s, monitor_id)) {
        error = ovsdb_syntax_error(monitor_id, NULL, "duplicate monitor ID");
        goto error;
    }

    m = xzalloc(sizeof *m);
    ovsdb_replica_init(&m->replica, &ovsdb_jsonrpc_replica_class);
    ovsdb_add_replica(db, &m->replica);
    m->session = s;
    m->db = db;
    hmap_insert(&s->monitors, &m->node, json_hash(monitor_id, 0));
    m->monitor_id = json_clone(monitor_id);
    shash_init(&m->tables);

    SHASH_FOR_EACH (node, json_object(monitor_requests)) {
        const struct ovsdb_table *table;
        struct ovsdb_jsonrpc_monitor_table *mt;
        size_t allocated_columns;
        const struct json *mr_value;
        size_t i;

        table = ovsdb_get_table(m->db, node->name);
        if (!table) {
            error = ovsdb_syntax_error(NULL, NULL,
                                       "no table named %s", node->name);
            goto error;
        }

        mt = xzalloc(sizeof *mt);
        mt->table = table;
        hmap_init(&mt->changes);
        shash_add(&m->tables, table->schema->name, mt);

        /* Parse columns. */
        mr_value = node->data;
        allocated_columns = 0;
        if (mr_value->type == JSON_ARRAY) {
            const struct json_array *array = &mr_value->u.array;

            for (i = 0; i < array->n; i++) {
                error = ovsdb_jsonrpc_parse_monitor_request(
                    mt, array->elems[i], &allocated_columns);
                if (error) {
                    goto error;
                }
            }
        } else {
            error = ovsdb_jsonrpc_parse_monitor_request(
                mt, mr_value, &allocated_columns);
            if (error) {
                goto error;
            }
        }

        /* Check for duplicate columns. */
        qsort(mt->columns, mt->n_columns, sizeof *mt->columns,
              compare_ovsdb_jsonrpc_monitor_column);
        for (i = 1; i < mt->n_columns; i++) {
            if (mt->columns[i].column == mt->columns[i - 1].column) {
                error = ovsdb_syntax_error(mr_value, NULL, "column %s "
                                           "mentioned more than once",
                                           mt->columns[i].column->name);
                goto error;
            }
        }
    }

    return ovsdb_jsonrpc_monitor_get_initial(m);

error:
    if (m) {
        ovsdb_remove_replica(m->db, &m->replica);
    }

    json = ovsdb_error_to_json(error);
    ovsdb_error_destroy(error);
    return json;
}

static struct jsonrpc_msg *
ovsdb_jsonrpc_monitor_cancel(struct ovsdb_jsonrpc_session *s,
                             struct json_array *params,
                             const struct json *request_id)
{
    if (params->n != 1) {
        return jsonrpc_create_error(json_string_create("invalid parameters"),
                                    request_id);
    } else {
        struct ovsdb_jsonrpc_monitor *m;

        m = ovsdb_jsonrpc_monitor_find(s, params->elems[0]);
        if (!m) {
            return jsonrpc_create_error(json_string_create("unknown monitor"),
                                        request_id);
        } else {
            ovsdb_remove_replica(m->db, &m->replica);
            return jsonrpc_create_reply(json_object_create(), request_id);
        }
    }
}

static void
ovsdb_jsonrpc_monitor_remove_all(struct ovsdb_jsonrpc_session *s)
{
    struct ovsdb_jsonrpc_monitor *m, *next;

    HMAP_FOR_EACH_SAFE (m, next, node, &s->monitors) {
        ovsdb_remove_replica(m->db, &m->replica);
    }
}

static struct ovsdb_jsonrpc_monitor *
ovsdb_jsonrpc_monitor_cast(struct ovsdb_replica *replica)
{
    ovs_assert(replica->class == &ovsdb_jsonrpc_replica_class);
    return CONTAINER_OF(replica, struct ovsdb_jsonrpc_monitor, replica);
}

struct ovsdb_jsonrpc_monitor_aux {
    const struct ovsdb_jsonrpc_monitor *monitor;
    struct ovsdb_jsonrpc_monitor_table *mt;
};

/* Finds and returns the ovsdb_jsonrpc_monitor_row in 'mt->changes' for the
 * given 'uuid', or NULL if there is no such row. */
static struct ovsdb_jsonrpc_monitor_row *
ovsdb_jsonrpc_monitor_row_find(const struct ovsdb_jsonrpc_monitor_table *mt,
                               const struct uuid *uuid)
{
    struct ovsdb_jsonrpc_monitor_row *row;

    HMAP_FOR_EACH_WITH_HASH (row, hmap_node, uuid_hash(uuid), &mt->changes) {
        if (uuid_equals(uuid, &row->uuid)) {
            return row;
        }
    }
    return NULL;
}

/* Allocates an array of 'mt->n_columns' ovsdb_datums and initializes them as
 * copies of the data in 'row' drawn from the columns represented by
 * mt->columns[].  Returns the array.
 *
 * If 'row' is NULL, returns NULL. */
static struct ovsdb_datum *
clone_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
                       const struct ovsdb_row *row)
{
    struct ovsdb_datum *data;
    size_t i;

    if (!row) {
        return NULL;
    }

    data = xmalloc(mt->n_columns * sizeof *data);
    for (i = 0; i < mt->n_columns; i++) {
        const struct ovsdb_column *c = mt->columns[i].column;
        const struct ovsdb_datum *src = &row->fields[c->index];
        struct ovsdb_datum *dst = &data[i];
        const struct ovsdb_type *type = &c->type;

        ovsdb_datum_clone(dst, src, type);
    }
    return data;
}

/* Replaces the mt->n_columns ovsdb_datums in row[] by copies of the data from
 * in 'row' drawn from the columns represented by mt->columns[]. */
static void
update_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
                        const struct ovsdb_row *row,
                        struct ovsdb_datum *data)
{
    size_t i;

    for (i = 0; i < mt->n_columns; i++) {
        const struct ovsdb_column *c = mt->columns[i].column;
        const struct ovsdb_datum *src = &row->fields[c->index];
        struct ovsdb_datum *dst = &data[i];
        const struct ovsdb_type *type = &c->type;

        if (!ovsdb_datum_equals(src, dst, type)) {
            ovsdb_datum_destroy(dst, type);
            ovsdb_datum_clone(dst, src, type);
        }
    }
}

/* Frees all of the mt->n_columns ovsdb_datums in data[], using the types taken
 * from mt->columns[], plus 'data' itself. */
static void
free_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
                      struct ovsdb_datum *data)
{
    if (data) {
        size_t i;

        for (i = 0; i < mt->n_columns; i++) {
            const struct ovsdb_column *c = mt->columns[i].column;

            ovsdb_datum_destroy(&data[i], &c->type);
        }
        free(data);
    }
}

/* Frees 'row', which must have been created from 'mt'. */
static void
ovsdb_jsonrpc_monitor_row_destroy(const struct ovsdb_jsonrpc_monitor_table *mt,
                                  struct ovsdb_jsonrpc_monitor_row *row)
{
    if (row) {
        free_monitor_row_data(mt, row->old);
        free_monitor_row_data(mt, row->new);
        free(row);
    }
}

static bool
ovsdb_jsonrpc_monitor_change_cb(const struct ovsdb_row *old,
                                const struct ovsdb_row *new,
                                const unsigned long int *changed OVS_UNUSED,
                                void *aux_)
{
    struct ovsdb_jsonrpc_monitor_aux *aux = aux_;
    const struct ovsdb_jsonrpc_monitor *m = aux->monitor;
    struct ovsdb_table *table = new ? new->table : old->table;
    const struct uuid *uuid = ovsdb_row_get_uuid(new ? new : old);
    struct ovsdb_jsonrpc_monitor_row *change;
    struct ovsdb_jsonrpc_monitor_table *mt;

    if (!aux->mt || table != aux->mt->table) {
        aux->mt = shash_find_data(&m->tables, table->schema->name);
        if (!aux->mt) {
            /* We don't care about rows in this table at all.  Tell the caller
             * to skip it.  */
            return false;
        }
    }
    mt = aux->mt;

    change = ovsdb_jsonrpc_monitor_row_find(mt, uuid);
    if (!change) {
        change = xmalloc(sizeof *change);
        hmap_insert(&mt->changes, &change->hmap_node, uuid_hash(uuid));
        change->uuid = *uuid;
        change->old = clone_monitor_row_data(mt, old);
        change->new = clone_monitor_row_data(mt, new);
    } else {
        if (new) {
            update_monitor_row_data(mt, new, change->new);
        } else {
            free_monitor_row_data(mt, change->new);
            change->new = NULL;

            if (!change->old) {
                /* This row was added then deleted.  Forget about it. */
                hmap_remove(&mt->changes, &change->hmap_node);
                free(change);
            }
        }
    }
    return true;
}

/* Returns JSON for a <row-update> (as described in RFC 7047) for 'row' within
 * 'mt', or NULL if no row update should be sent.
 *
 * The caller should specify 'initial' as true if the returned JSON is going to
 * be used as part of the initial reply to a "monitor" request, false if it is
 * going to be used as part of an "update" notification.
 *
 * 'changed' must be a scratch buffer for internal use that is at least
 * bitmap_n_bytes(mt->n_columns) bytes long. */
static struct json *
ovsdb_jsonrpc_monitor_compose_row_update(
    const struct ovsdb_jsonrpc_monitor_table *mt,
    const struct ovsdb_jsonrpc_monitor_row *row,
    bool initial, unsigned long int *changed)
{
    enum ovsdb_jsonrpc_monitor_selection type;
    struct json *old_json, *new_json;
    struct json *row_json;
    size_t i;

    type = (initial ? OJMS_INITIAL
            : !row->old ? OJMS_INSERT
            : !row->new ? OJMS_DELETE
            : OJMS_MODIFY);
    if (!(mt->select & type)) {
        return NULL;
    }

    if (type == OJMS_MODIFY) {
        size_t n_changes;

        n_changes = 0;
        memset(changed, 0, bitmap_n_bytes(mt->n_columns));
        for (i = 0; i < mt->n_columns; i++) {
            const struct ovsdb_column *c = mt->columns[i].column;
            if (!ovsdb_datum_equals(&row->old[i], &row->new[i], &c->type)) {
                bitmap_set1(changed, i);
                n_changes++;
            }
        }
        if (!n_changes) {
            /* No actual changes: presumably a row changed and then
             * changed back later. */
            return NULL;
        }
    }

    row_json = json_object_create();
    old_json = new_json = NULL;
    if (type & (OJMS_DELETE | OJMS_MODIFY)) {
        old_json = json_object_create();
        json_object_put(row_json, "old", old_json);
    }
    if (type & (OJMS_INITIAL | OJMS_INSERT | OJMS_MODIFY)) {
        new_json = json_object_create();
        json_object_put(row_json, "new", new_json);
    }
    for (i = 0; i < mt->n_columns; i++) {
        const struct ovsdb_jsonrpc_monitor_column *c = &mt->columns[i];

        if (!(type & c->select)) {
            /* We don't care about this type of change for this
             * particular column (but we will care about it for some
             * other column). */
            continue;
        }

        if ((type == OJMS_MODIFY && bitmap_is_set(changed, i))
            || type == OJMS_DELETE) {
            json_object_put(old_json, c->column->name,
                            ovsdb_datum_to_json(&row->old[i],
                                                &c->column->type));
        }
        if (type & (OJMS_INITIAL | OJMS_INSERT | OJMS_MODIFY)) {
            json_object_put(new_json, c->column->name,
                            ovsdb_datum_to_json(&row->new[i],
                                                &c->column->type));
        }
    }

    return row_json;
}

/* Constructs and returns JSON for a <table-updates> object (as described in
 * RFC 7047) for all the outstanding changes within 'monitor', and deletes all
 * the outstanding changes from 'monitor'.  Returns NULL if no update needs to
 * be sent.
 *
 * The caller should specify 'initial' as true if the returned JSON is going to
 * be used as part of the initial reply to a "monitor" request, false if it is
 * going to be used as part of an "update" notification. */
static struct json *
ovsdb_jsonrpc_monitor_compose_table_update(
    const struct ovsdb_jsonrpc_monitor *monitor, bool initial)
{
    struct shash_node *node;
    unsigned long int *changed;
    struct json *json;
    size_t max_columns;

    max_columns = 0;
    SHASH_FOR_EACH (node, &monitor->tables) {
        struct ovsdb_jsonrpc_monitor_table *mt = node->data;

        max_columns = MAX(max_columns, mt->n_columns);
    }
    changed = xmalloc(bitmap_n_bytes(max_columns));

    json = NULL;
    SHASH_FOR_EACH (node, &monitor->tables) {
        struct ovsdb_jsonrpc_monitor_table *mt = node->data;
        struct ovsdb_jsonrpc_monitor_row *row, *next;
        struct json *table_json = NULL;

        HMAP_FOR_EACH_SAFE (row, next, hmap_node, &mt->changes) {
            struct json *row_json;

            row_json = ovsdb_jsonrpc_monitor_compose_row_update(
                mt, row, initial, changed);
            if (row_json) {
                char uuid[UUID_LEN + 1];

                /* Create JSON object for transaction overall. */
                if (!json) {
                    json = json_object_create();
                }

                /* Create JSON object for transaction on this table. */
                if (!table_json) {
                    table_json = json_object_create();
                    json_object_put(json, mt->table->schema->name, table_json);
                }

                /* Add JSON row to JSON table. */
                snprintf(uuid, sizeof uuid, UUID_FMT, UUID_ARGS(&row->uuid));
                json_object_put(table_json, uuid, row_json);
            }

            hmap_remove(&mt->changes, &row->hmap_node);
            ovsdb_jsonrpc_monitor_row_destroy(mt, row);
        }
    }

    free(changed);

    return json;
}

static bool
ovsdb_jsonrpc_monitor_needs_flush(struct ovsdb_jsonrpc_session *s)
{
    struct ovsdb_jsonrpc_monitor *m;

    HMAP_FOR_EACH (m, node, &s->monitors) {
        struct shash_node *node;

        SHASH_FOR_EACH (node, &m->tables) {
            struct ovsdb_jsonrpc_monitor_table *mt = node->data;

            if (!hmap_is_empty(&mt->changes)) {
                return true;
            }
        }
    }

    return false;
}

static void
ovsdb_jsonrpc_monitor_flush_all(struct ovsdb_jsonrpc_session *s)
{
    struct ovsdb_jsonrpc_monitor *m;

    HMAP_FOR_EACH (m, node, &s->monitors) {
        struct json *json;

        json = ovsdb_jsonrpc_monitor_compose_table_update(m, false);
        if (json) {
            struct jsonrpc_msg *msg;
            struct json *params;

            params = json_array_create_2(json_clone(m->monitor_id), json);
            msg = jsonrpc_create_notify("update", params);
            jsonrpc_session_send(s->js, msg);
        }
    }
}

static void
ovsdb_jsonrpc_monitor_init_aux(struct ovsdb_jsonrpc_monitor_aux *aux,
                               const struct ovsdb_jsonrpc_monitor *m)
{
    aux->monitor = m;
    aux->mt = NULL;
}

static struct ovsdb_error *
ovsdb_jsonrpc_monitor_commit(struct ovsdb_replica *replica,
                             const struct ovsdb_txn *txn,
                             bool durable OVS_UNUSED)
{
    struct ovsdb_jsonrpc_monitor *m = ovsdb_jsonrpc_monitor_cast(replica);
    struct ovsdb_jsonrpc_monitor_aux aux;

    ovsdb_jsonrpc_monitor_init_aux(&aux, m);
    ovsdb_txn_for_each_change(txn, ovsdb_jsonrpc_monitor_change_cb, &aux);

    return NULL;
}

static struct json *
ovsdb_jsonrpc_monitor_get_initial(const struct ovsdb_jsonrpc_monitor *m)
{
    struct ovsdb_jsonrpc_monitor_aux aux;
    struct shash_node *node;
    struct json *json;

    ovsdb_jsonrpc_monitor_init_aux(&aux, m);
    SHASH_FOR_EACH (node, &m->tables) {
        struct ovsdb_jsonrpc_monitor_table *mt = node->data;

        if (mt->select & OJMS_INITIAL) {
            struct ovsdb_row *row;

            HMAP_FOR_EACH (row, hmap_node, &mt->table->rows) {
                ovsdb_jsonrpc_monitor_change_cb(NULL, row, NULL, &aux);
            }
        }
    }
    json = ovsdb_jsonrpc_monitor_compose_table_update(m, true);
    return json ? json : json_object_create();
}

static void
ovsdb_jsonrpc_monitor_destroy(struct ovsdb_replica *replica)
{
    struct ovsdb_jsonrpc_monitor *m = ovsdb_jsonrpc_monitor_cast(replica);
    struct shash_node *node;

    json_destroy(m->monitor_id);
    SHASH_FOR_EACH (node, &m->tables) {
        struct ovsdb_jsonrpc_monitor_table *mt = node->data;
        struct ovsdb_jsonrpc_monitor_row *row, *next;

        HMAP_FOR_EACH_SAFE (row, next, hmap_node, &mt->changes) {
            hmap_remove(&mt->changes, &row->hmap_node);
            ovsdb_jsonrpc_monitor_row_destroy(mt, row);
        }
        hmap_destroy(&mt->changes);

        free(mt->columns);
        free(mt);
    }
    shash_destroy(&m->tables);
    hmap_remove(&m->session->monitors, &m->node);
    free(m);
}

static const struct ovsdb_replica_class ovsdb_jsonrpc_replica_class = {
    ovsdb_jsonrpc_monitor_commit,
    ovsdb_jsonrpc_monitor_destroy
};


text:
namespace cc {

class LayerTreeHostSingleThreadClient {
 public:
  // Request that the client schedule a composite. For tests using single thread
  // without a scheduler.
  virtual void RequestScheduleComposite() {}

  // Called whenever the begin frame interval changes. This interval can be used
  // for animations.
  virtual void FrameIntervalUpdated(base::TimeDelta interval) {}

  // Called whenever the compositor submits a CompositorFrame. Afterward,
  // LayerTreeHostClient::DidReceiveCompositorFrameAck() will be called once the
  // display compositor/ finishes processing the frame. So these functions can
  // be used to keep track of pending submitted CompositorFrames for rate
  // limiting.
  virtual void DidSubmitCompositorFrame() = 0;

  // Called when the active LayerTreeFrameSink is lost and needs to be
  // replaced. This allows the embedder to schedule a composite which will
  // run the machinery to acquire a new LayerTreeFrameSink.
  virtual void DidLoseLayerTreeFrameSink() = 0;

 protected:
  virtual ~LayerTreeHostSingleThreadClient() {}
};

}  // namespace cc

#endif  // CC_TREES_LAYER_TREE_HOST_SINGLE_THREAD_CLIENT_H_


text:
using System;
using MonoMac.ObjCRuntime;
using MonoMac.Foundation;

namespace MonoMac.AppKit
{
	[Register ("__monomac_internal_ActionDispatcher")]
	internal class ActionDispatcher : NSObject
	{
		const string skey = "__monomac_internal_ActionDispatcher_activated:";
		const string dkey = "__monomac_internal_ActionDispatcher_doubleActivated:";
		public static Selector Action = new Selector (skey);
		public static Selector DoubleAction = new Selector (dkey);
		public EventHandler Activated;
		public EventHandler DoubleActivated;

		[Export (skey)]
		public void OnActivated (NSObject sender)
		{
			if (Activated != null)
				Activated (sender, EventArgs.Empty);
		}

		[Export (dkey)]
		public void OnActivated2 (NSObject sender)
		{
			if (DoubleActivated != null)
				DoubleActivated (sender, EventArgs.Empty);
		}

		public ActionDispatcher (EventHandler handler)
		{
			Activated = handler;
		}

		public ActionDispatcher ()
		{
		}

		public static NSObject SetupAction (NSObject target, EventHandler handler)
		{
			ActionDispatcher ctarget = target as ActionDispatcher;
			if (ctarget == null){
				ctarget = new ActionDispatcher ();
				ctarget.Activated += handler;
			}
			return ctarget;
		}

		public static void RemoveAction (NSObject target, EventHandler handler)
		{
			ActionDispatcher ctarget = target as ActionDispatcher;
			if (ctarget == null)
				return;
			ctarget.Activated -= handler;
		}

		public static NSObject SetupDoubleAction (NSObject target, EventHandler doubleHandler)
		{
			ActionDispatcher ctarget = target as ActionDispatcher;
			if (ctarget == null){
				ctarget = new ActionDispatcher ();
				ctarget.DoubleActivated += doubleHandler;
			}
			return ctarget;
		}

		public static void RemoveDoubleAction (NSObject target, EventHandler doubleHandler)
		{
			ActionDispatcher ctarget = target as ActionDispatcher;
			if (ctarget == null)
				return;
			ctarget.DoubleActivated -= doubleHandler;
		}
	}
}


text:
from bottle import Bottle
from bottle import route, request, response, template
import os
import MySQLdb
import time
import cloudstorage as gcs
from test.assignment2 import *
from google.appengine.api import app_identity
import re
import datetime
from collections import defaultdict
# Note: We don't need to call run() since our application is embedded within
# the App Engine WSGI application server.

bottle = Bottle()

@bottle.route('/')
def hello():
    """Return a friendly HTTP greeting."""
    env = os.getenv('SERVER_SOFTWARE')
    main_string = "Time to Insert data ::"
    try:
        bucket_name = os.environ.get('BUCKET_NAME',app_identity.get_default_gcs_bucket_name())
        #file_name = "/"+bucket_name+"/all_month.csv"
        file_name = "/"+bucket_name+"/demo-testfile.csv"
        #content = read_file(file_name)
        db = get_connection(env)
        cursor = db.cursor()
        cursor = initialise_db(cursor)
        s_time = time.time()
        insert_into_table(cursor,file_name)
        db.commit()
        e_time = time.time()
        t_time = str(e_time-s_time)
        mag_5 = len(get_eq_gr_mag(cursor ,5))
        mag_4 = len(get_eq_gr_mag(cursor ,4))
        mag_3 = len(get_eq_gr_mag(cursor, 3))
        mag_2 = len(get_eq_gr_mag(cursor, 2))
        m_5 = len(get_eq_equal_mag(cursor,5))
        m_4 = len(get_eq_equal_mag(cursor,4))
        m_3 = len(get_eq_equal_mag(cursor,3))
        m_2 = len(get_eq_equal_mag(cursor,2))
        rows = get_eq_gr_mag(cursor ,5)
        result_string= filter_result(rows)
        output = ""
        output += "
"+main_string+str(t_time)+"
"
        output += "
Number of earthquakes greater than maginitude 5: "+str(mag_5)+"
"
        output += "
Number of earthquakes greater than maginitude 4: "+str(mag_4)+"
"
        output += "
Number of earthquakes greater than maginitude 3: "+str(mag_3)+"
"
        output += "
Number of earthquakes greater than maginitude 2: "+str(mag_2)+"
"
        output += "
Number of earthquakes equal to maginitude 5: "+str(m_5)+"
"
        output += "
Number of earthquakes equal to maginitude 4: "+str(m_4)+"
"
        output += "
Number of earthquakes equal to maginitude 3: "+str(m_3)+"
"
        output += "
Number of earthquakes equal to maginitude 2: "+str(m_2)+"
"
        return output+"
Number of Earthquakes per each week of maginitude greater than 2
"+result_string+"
"
    except Exception as e:
        return str(e)

def get_connection(type_of_con):
    try:
        if (type_of_con and type_of_con.startswith('Google App Engine/')):
            db = MySQLdb.connect(unix_socket='/cloudsql/cloudcomputing1-970:mysql-server-1',user='root')
            return db
        else:
            con = mdb.connect('localhost', 'root', 'root', 'test');
            return con
    except Exception as e:
        print "Connection to the database failed : "+str(e)

def initialise_db(cursor):
    try:
        result2 = cursor.execute('CREATE DATABASE IF NOT EXISTS test')
        result2 = cursor.execute('use test')
        result2 = cursor.execute('CREATE TABLE IF NOT EXISTS EARTHQUAKES (time TIMESTAMP,latitude DOUBLE PRECISION(15,7),longitude DOUBLE PRECISION(15,7),depth DOUBLE ,mag DOUBLE,magType varchar(255),nst VARCHAR(255),gap VARCHAR(255),dmin VARCHAR(255),rms VARCHAR(255),net varchar(255), id varchar(255),updated TIMESTAMP,place varchar(255),type varchar(255))')
        result2 = cursor.execute("truncate EARTHQUAKES");
        result2 = cursor.execute("ALTER TABLE EARTHQUAKES ADD PRIMARY KEY (id)");
    except Exception as e:
        print "Reinitialisation of the tables :: "+str(e)
    return cursor

def read_file(filename):
    gcs_file = gcs.open(filename)
    content = ""
    for line in gcs_file:
        content += line
    return content

def filter_result(result):
    weeks_dic = defaultdict(int)
    result_string = ""
    for row in result:
        date = row[0]
        week = get_week(date.year,date.month,date.day)
        month_week = "Month:"+str(date.month)+":week:"+str(week)
        weeks_dic[month_week]+=1
        print date,week
    for key in sorted(weeks_dic):
        result_string += key+": "+str(weeks_dic[key])+"
"
    return result_string

def get_week(year, month, day):
    first_week_month = datetime.datetime(year, month, 1).isocalendar()[1]
    if month == 1 and first_week_month > 10:
        first_week_month = 0
    user_date = datetime.datetime(year, month, day).isocalendar()[1]
    if month == 1 and user_date > 10:
        user_date = 0
    return user_date - first_week_month+1

def insert_into_table(cursor,filename):
    to_insert={}
    gcs_file = gcs.open(filename)
    try:
        for line in gcs_file:
            fields = line.split(",")
            if(fields[0]=="time"):
                continue
            else:
                to_insert['time'] = fields[0]
                to_insert['latitude'] = float(fields[1])
                to_insert['longitude'] = float(fields[2])
                to_insert['depth'] = float(fields[3])
                to_insert['mag'] = float(fields[4])
                to_insert['magtype'] = fields[5]
                to_insert['nst'] = fields[6]
                to_insert['gap'] = fields[7]
                to_insert['dmin'] = fields[8]
                to_insert['rms'] = fields[9]
                to_insert['net'] = fields[10]
                to_insert['idn'] = fields[11]
                to_insert['updated'] = fields[12]
                to_insert['place'] = fields[13].replace("'","").replace("\"","")
                to_insert['type_of'] = fields[14].strip("\n")
                query = create_insert(to_insert)
                #print query
                cur_r = cursor.execute(query)
    except Exception as e:
        print "Duplicate entries "+str(e)

def create_insert(to_insert):
    formated_time = format_time(to_insert['time'])
    formated_updated = format_time(to_insert['updated'])
    query = "INSERT INTO EARTHQUAKES(time,latitude,longitude,depth,mag,magtype,nst,gap,dmin,rms,net,id,updated,place,type) VALUES("
    query += "'"+formated_time+"'"+","
    query += str(to_insert['latitude'])+","
    query += str(to_insert['longitude'])+","
    query += str(to_insert['depth'])+","
    query += str(to_insert['mag'])+","
    query += "'"+to_insert['magtype']+"'"+","
    query += "'"+to_insert['nst']+"'"+","
    query += "'"+to_insert['gap']+"'"+","
    query += "'"+to_insert['dmin']+"'"+","
    query += "'"+to_insert['rms']+"'"+","
    query += "'"+to_insert['net']+"'"+","
    query += "'"+to_insert['idn']+"'"+","
    query += "'"+formated_updated+"'"+","
    query += "'"+to_insert['place'].rstrip("\"")+"'"+","
    query += "'"+to_insert['type_of']+"'"+")"
    return query

def format_time(time_string):
    date = time_string.split("T")[0]
    time = time_string.split("T")[1]
    #2008-01-01 00:00:01
    return date+" "+time.split(".")[0]

def get_eq_gr_mag(cursor ,magnitude):
    cursor.execute("SELECT * FROM EARTHQUAKES WHERE mag >"+str(magnitude))
    rows = cursor.fetchall()
    return rows

def get_eq_equal_mag(cursor,magnitude):
    cursor.execute("SELECT * FROM EARTHQUAKES WHERE mag ="+str(magnitude))
    rows = cursor.fetchall()
    return rows

@bottle.route('/upload')
def upload(name="User"):
    return template('upload_template', name=name)

@bottle.route('/doupload',  method='POST')
def doupload(time_taken=0):
    start_time = time.time()
    bucket_name = os.environ.get('BUCKET_NAME',app_identity.get_default_gcs_bucket_name())
    filename = '/'+bucket_name+ '/demo-testfile.csv'
    #upload = request.files.get('upload')
    data = request.files.get('data')
    raw = data.file.read()
    write_retry_params = gcs.RetryParams(backoff_factor=1.1)
    gcs_file = gcs.open(filename,'w',content_type='text/plain',options={'x-goog-meta-foo': 'foo','x-goog-meta-bar': 'bar'},retry_params=write_retry_params)
    gcs_file.write(raw)
    gcs_file.close()
    end_time = time.time()
    time_taken = end_time-start_time
    #print len(data)
    return template('doupload_template',time_taken=time_taken)

# Define an handler for 404 errors.
@bottle.error(404)
def error_404(error):
    """Return a custom 404 error."""
    return 'Sorry, nothing at this URL.'


text:
/*
 * 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 io.trino.execution.scheduler;

import java.io.Closeable;

public interface StageScheduler
        extends Closeable
{
    /**
     * Schedules as much work as possible without blocking.
     * The schedule results is a hint to the query scheduler if and
     * when the stage scheduler should be invoked again.  It is
     * important to note that this is only a hint and the query
     * scheduler may call the schedule method at any time.
     */
    ScheduleResult schedule();

    @Override
    default void close() {}
}


text:
var events = require('./database').collection('events');

module.exports = function(uuid) {

  var newTimestamp = new Date().getTime();
  var cursor = events.find({
    $or: [{fromUuid: uuid}, {uuid:uuid}, { devices: {$in: [uuid, "all", "*"]}}],
    timestamp: { $gt : newTimestamp }
  }, {}, {tailable:true, timeout:false});

  return cursor;

};


text:
@interface BuddyItem ()

-(NSData *)_returnImageDataFromString:(NSString *) imageStr;
-(NSString *) _returnImageString:(NSString *)str;

@end

@implementation BuddyItem

-(id) initWithPresence:(XMPPPresence *)presence{
    self = [self init];
    if (self) {
        self.buddyName = presence.from.user;
        self.buddyStatus = presence.status;
        self.buddyResource = presence.show;

    }
    return self;
}
-(id) initWithBuddyDict:(NSDictionary * ) dict{
    self = [self init];
    if (self) {
        self.buddyName = [dict objectForKey:@"username"];
        self.headerImage = [UIImage imageWithData:[self _returnImageDataFromString:[self _returnImageString:[dict objectForKey:@"vcard"]]]];
    }
    return self;
}

-(NSData *)_returnImageDataFromString:(NSString *) imageStr{
    NSData * imageData = nil;
//    imageData = [NSData dataWithContentsOfFile:imageStr];
    imageData = [[NSData alloc]initWithBase64Encoding:imageStr];
    return [imageData autorelease];
}
-(NSString *) _returnImageString:(NSString *)str{
    NSLog(@"%@",str);
    NSRange range = [str rangeOfString:@"<BINVAL>"];
    range.location = range.location+range.length;
    range.length = str.length - range.location;
    str = [str substringWithRange:range];
//    NSLog(@"%@",str);
    range = [str rangeOfString:@"</BINVAL>"];
    range.length = range.location;
    range.location = 0;
    str = [str substringWithRange:range];
//    NSLog(@"%@",str);
    return str;
}
-(void)dealloc{
    [self.headerImage release];
    [self.buddyName release];
//    self.buddyName = nil;
//    self.headerImage = nil;
    [super dealloc];
}
@end


text:
DEPRECATED
=========

pick impressive colors from image, canvas for nodejs, browser.

I'm preparing demopage.

### use node
you have to install (node-canvas)[https://github.com/Automattic/node-canvas]
```javascript
var fs = require("fs");
var Canvas = require("canvas");
var Image = Canvas.Image;
var Impression = require("impression");
var imageData = fs.readFileSync("path/to/image");
var image = new Image();
image.src = imageData;
var imp = Impression(image);
imp.dominantColor.toRGB();
imp.pickedColors.toHexString();
imp.highSatColors.toRGB();
imp.chromaColors.toHexString();
imp.achromaColors.toRGB();
/*get [{r: 255, g: 255, b: 0}, ... ]
  or .toHexString()
  get ["#FFFF00", ...]*/
```

### use browser

```javascript

```
### use requirejs
```javascript

```


text:
#include "interface_idds.h"
#include "PluginsManagerComponent.h"
#include "BuilderElementsComponent.h"
#include "NetworkTrainersComponent.h"

CComponentsContainer::CComponentsContainer(void)
{
	pAppController = NULL;
}

CComponentsContainer::~CComponentsContainer(void)
{
	ReleaseComponetsTable();
}

void CComponentsContainer::FillComponentsTable()
{
	// Adding Plugins Manager Component
	CPluginsManagerComponent* pPMComponent = new CPluginsManagerComponent;
	IComponent* pComponent = NULL;
	pPMComponent->QueryInterface(IDD_IComponent, (void**)&pComponent);
	if (pComponent)
	{
		pComponent->SetAppController(pAppController);
		mComponents.AddTail(pComponent);
	}

	CBuilderElementsComponent* pBMComponent = new CBuilderElementsComponent;
	pComponent = NULL;
	pBMComponent->QueryInterface(IDD_IComponent, (void**)&pComponent);
	if (pComponent)
	{
		pComponent->SetAppController(pAppController);
		mComponents.AddTail(pComponent);
	}

	CNetworkTrainersComponent* pNTComponent = new CNetworkTrainersComponent;
	pComponent = NULL;
	pNTComponent->QueryInterface(IDD_IComponent, (void**)&pComponent);
	if (pComponent)
	{
		pComponent->SetAppController(pAppController);
		mComponents.AddTail(pComponent);
	}
}

void CComponentsContainer::ReleaseComponetsTable()
{
	for(;mComponents.GetCount() > 0;)
	{
		IComponent* pComponent = mComponents.GetHead();
		mComponents.RemoveHead();
		delete pComponent;
	}
}

IComponent*	CComponentsContainer::GetComponentByName(CString& csComponentName)
{
	for(POSITION pos = mComponents.GetHeadPosition();pos;)
	{
		IComponent* pComponent = mComponents.GetNext(pos);
		if (csComponentName == pComponent->GetComponentName())
			return pComponent;
	}

	return NULL;
}

void CComponentsContainer::SetAppController(IAppController* pController)
{
	pAppController = pController;
}


text:
package org.apache.camel.core.xml;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.apache.camel.ThreadPoolRejectedPolicy;
import org.apache.camel.builder.ThreadPoolProfileBuilder;
import org.apache.camel.builder.xml.TimeUnitAdapter;
import org.apache.camel.spi.ThreadPoolProfile;
import org.apache.camel.util.CamelContextHelper;

/**
 * A factory which instantiates {@link java.util.concurrent.ExecutorService} objects
 *
 * @version
 */
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class AbstractCamelThreadPoolFactoryBean extends AbstractCamelFactoryBean<ExecutorService> {

    @XmlAttribute(required = true)
    private String poolSize;
    @XmlAttribute
    private String maxPoolSize;
    @XmlAttribute
    private String keepAliveTime;
    @XmlAttribute
    @XmlJavaTypeAdapter(TimeUnitAdapter.class)
    private TimeUnit timeUnit = TimeUnit.SECONDS;
    @XmlAttribute
    private String maxQueueSize;
    @XmlAttribute
    private ThreadPoolRejectedPolicy rejectedPolicy = ThreadPoolRejectedPolicy.CallerRuns;
    @XmlAttribute(required = true)
    private String threadName;
    @XmlAttribute
    private Boolean scheduled;

    public ExecutorService getObject() throws Exception {
        int size = CamelContextHelper.parseInteger(getCamelContext(), poolSize);
        if (size <= 0) {
            throw new IllegalArgumentException("PoolSize must be a positive number");
        }

        int max = size;
        if (maxPoolSize != null) {
            max = CamelContextHelper.parseInteger(getCamelContext(), maxPoolSize);
        }

        long keepAlive = 60;
        if (keepAliveTime != null) {
            keepAlive = CamelContextHelper.parseLong(getCamelContext(), keepAliveTime);
        }

        int queueSize = -1;
        if (maxQueueSize != null) {
            queueSize = CamelContextHelper.parseInteger(getCamelContext(), maxQueueSize);
        }

        ThreadPoolProfile profile = new ThreadPoolProfileBuilder(getId())
                .poolSize(size)
                .maxPoolSize(max)
                .keepAliveTime(keepAlive, timeUnit)
                .maxQueueSize(queueSize)
                .rejectedPolicy(rejectedPolicy)
                .build();

        ExecutorService answer;
        if (scheduled != null && scheduled) {
            answer = getCamelContext().getExecutorServiceManager().newScheduledThreadPool(getId(), getThreadName(), profile);
        } else {
            answer = getCamelContext().getExecutorServiceManager().newThreadPool(getId(), getThreadName(), profile);
        }
        return answer;
    }

    public Class<ExecutorService> getObjectType() {
        return ExecutorService.class;
    }

    public String getPoolSize() {
        return poolSize;
    }

    public void setPoolSize(String poolSize) {
        this.poolSize = poolSize;
    }

    public String getMaxPoolSize() {
        return maxPoolSize;
    }

    public void setMaxPoolSize(String maxPoolSize) {
        this.maxPoolSize = maxPoolSize;
    }

    public String getKeepAliveTime() {
        return keepAliveTime;
    }

    public void setKeepAliveTime(String keepAliveTime) {
        this.keepAliveTime = keepAliveTime;
    }

    public TimeUnit getTimeUnit() {
        return timeUnit;
    }

    public void setTimeUnit(TimeUnit timeUnit) {
        this.timeUnit = timeUnit;
    }

    public String getMaxQueueSize() {
        return maxQueueSize;
    }

    public void setMaxQueueSize(String maxQueueSize) {
        this.maxQueueSize = maxQueueSize;
    }

    public ThreadPoolRejectedPolicy getRejectedPolicy() {
        return rejectedPolicy;
    }

    public void setRejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
        this.rejectedPolicy = rejectedPolicy;
    }

    public String getThreadName() {
        return threadName;
    }

    public void setThreadName(String threadName) {
        this.threadName = threadName;
    }

    public Boolean getScheduled() {
        return scheduled;
    }

    public void setScheduled(Boolean scheduled) {
        this.scheduled = scheduled;
    }
}


text:
using System.Runtime.Serialization;

namespace SMSApi.Api.Response
{
    [DataContract]
    public class Groups : BasicCollection<Group>
    {
        private Groups() : base() { }
    }
}


text:
/*
=require foundation/foundation
=require foundation/foundation.alerts
=require foundation/foundation.clearing
=require foundation/foundation.cookie
=require foundation/foundation.dropdown
=require foundation/foundation.forms
=require foundation/foundation.joyride
=require foundation/foundation.magellan
=require foundation/foundation.orbit
=require foundation/foundation.placeholder
=require foundation/foundation.reveal
=require foundation/foundation.section
=require foundation/foundation.tooltips
=require foundation/foundation.topbar
*/


text:
<?php

namespace Ron\ConsumptionBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * WaterRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class WaterRepository extends EntityRepository
{
}