text:
#include "src/core/surface/server.h"

#include <stdlib.h>
#include <string.h>

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>

#include "src/core/channel/census_filter.h"
#include "src/core/channel/channel_args.h"
#include "src/core/channel/connected_channel.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/support/stack_lockfree.h"
#include "src/core/support/string.h"
#include "src/core/surface/call.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/completion_queue.h"
#include "src/core/surface/init.h"
#include "src/core/transport/metadata.h"

typedef struct listener {
  void *arg;
  void (*start)(grpc_server *server, void *arg, grpc_pollset **pollsets,
                size_t pollset_count);
  void (*destroy)(grpc_server *server, void *arg);
  struct listener *next;
} listener;

typedef struct call_data call_data;
typedef struct channel_data channel_data;
typedef struct registered_method registered_method;

typedef struct {
  call_data *next;
  call_data *prev;
} call_link;

typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type;

typedef struct requested_call {
  requested_call_type type;
  void *tag;
  grpc_server *server;
  grpc_completion_queue *cq_bound_to_call;
  grpc_completion_queue *cq_for_notification;
  grpc_call **call;
  grpc_cq_completion completion;
  union {
    struct {
      grpc_call_details *details;
      grpc_metadata_array *initial_metadata;
    } batch;
    struct {
      registered_method *registered_method;
      gpr_timespec *deadline;
      grpc_metadata_array *initial_metadata;
      grpc_byte_buffer **optional_payload;
    } registered;
  } data;
} requested_call;

typedef struct channel_registered_method {
  registered_method *server_registered_method;
  grpc_mdstr *method;
  grpc_mdstr *host;
} channel_registered_method;

struct channel_data {
  grpc_server *server;
  grpc_connectivity_state connectivity_state;
  grpc_channel *channel;
  grpc_mdstr *path_key;
  grpc_mdstr *authority_key;
  /* linked list of all channels on a server */
  channel_data *next;
  channel_data *prev;
  channel_registered_method *registered_methods;
  gpr_uint32 registered_method_slots;
  gpr_uint32 registered_method_max_probes;
  grpc_iomgr_closure finish_destroy_channel_closure;
  grpc_iomgr_closure channel_connectivity_changed;
};

typedef struct shutdown_tag {
  void *tag;
  grpc_completion_queue *cq;
  grpc_cq_completion completion;
} shutdown_tag;

typedef enum {
  /* waiting for metadata */
  NOT_STARTED,
  /* inital metadata read, not flow controlled in yet */
  PENDING,
  /* flow controlled in, on completion queue */
  ACTIVATED,
  /* cancelled before being queued */
  ZOMBIED
} call_state;

typedef struct request_matcher request_matcher;

struct call_data {
  grpc_call *call;

  /** protects state */
  gpr_mu mu_state;
  /** the current state of a call - see call_state */
  call_state state;

  grpc_mdstr *path;
  grpc_mdstr *host;
  gpr_timespec deadline;
  int got_initial_metadata;

  grpc_completion_queue *cq_new;

  grpc_stream_op_buffer *recv_ops;
  grpc_stream_state *recv_state;
  grpc_iomgr_closure *on_done_recv;

  grpc_iomgr_closure server_on_recv;
  grpc_iomgr_closure kill_zombie_closure;

  call_data *pending_next;
};

struct request_matcher {
  call_data *pending_head;
  call_data *pending_tail;
  gpr_stack_lockfree *requests;
};

struct registered_method {
  char *method;
  char *host;
  request_matcher request_matcher;
  registered_method *next;
};

typedef struct {
  grpc_channel **channels;
  size_t num_channels;
} channel_broadcaster;

struct grpc_server {
  size_t channel_filter_count;
  const grpc_channel_filter **channel_filters;
  grpc_channel_args *channel_args;

  grpc_completion_queue **cqs;
  grpc_pollset **pollsets;
  size_t cq_count;

  /* The two following mutexes control access to server-state
     mu_global controls access to non-call-related state (e.g., channel state)
     mu_call controls access to call-related state (e.g., the call lists)

     If they are ever required to be nested, you must lock mu_global
     before mu_call. This is currently used in shutdown processing
     (grpc_server_shutdown_and_notify and maybe_finish_shutdown) */
  gpr_mu mu_global; /* mutex for server and channel state */
  gpr_mu mu_call;   /* mutex for call-specific state */

  registered_method *registered_methods;
  request_matcher unregistered_request_matcher;
  /** free list of available requested_calls indices */
  gpr_stack_lockfree *request_freelist;
  /** requested call backing data */
  requested_call *requested_calls;
  int max_requested_calls;

  gpr_atm shutdown_flag;
  gpr_uint8 shutdown_published;
  size_t num_shutdown_tags;
  shutdown_tag *shutdown_tags;

  channel_data root_channel_data;

  listener *listeners;
  int listeners_destroyed;
  gpr_refcount internal_refcount;

  /** when did we print the last shutdown progress message */
  gpr_timespec last_shutdown_message_time;
};

#define SERVER_FROM_CALL_ELEM(elem) \
  (((channel_data *)(elem)->channel_data)->server)

static void begin_call(grpc_server *server, call_data *calld,
                       requested_call *rc);
static void fail_call(grpc_server *server, requested_call *rc);
/* Before calling maybe_finish_shutdown, we must hold mu_global and not
   hold mu_call */
static void maybe_finish_shutdown(grpc_server *server);

/*
 * channel broadcaster
 */

/* assumes server locked */
static void channel_broadcaster_init(grpc_server *s, channel_broadcaster *cb) {
  channel_data *c;
  size_t count = 0;
  for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) {
    count++;
  }
  cb->num_channels = count;
  cb->channels = gpr_malloc(sizeof(*cb->channels) * cb->num_channels);
  count = 0;
  for (c = s->root_channel_data.next; c != &s->root_channel_data; c = c->next) {
    cb->channels[count++] = c->channel;
    GRPC_CHANNEL_INTERNAL_REF(c->channel, "broadcast");
  }
}

struct shutdown_cleanup_args {
  grpc_iomgr_closure closure;
  gpr_slice slice;
};

static void shutdown_cleanup(void *arg, int iomgr_status_ignored) {
  struct shutdown_cleanup_args *a = arg;
  gpr_slice_unref(a->slice);
  gpr_free(a);
}

static void send_shutdown(grpc_channel *channel, int send_goaway,
                          int send_disconnect) {
  grpc_transport_op op;
  struct shutdown_cleanup_args *sc;
  grpc_channel_element *elem;

  memset(&op, 0, sizeof(op));
  op.send_goaway = send_goaway;
  sc = gpr_malloc(sizeof(*sc));
  sc->slice = gpr_slice_from_copied_string("Server shutdown");
  op.goaway_message = &sc->slice;
  op.goaway_status = GRPC_STATUS_OK;
  op.disconnect = send_disconnect;
  grpc_iomgr_closure_init(&sc->closure, shutdown_cleanup, sc);
  op.on_consumed = &sc->closure;

  elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
  elem->filter->start_transport_op(elem, &op);
}

static void channel_broadcaster_shutdown(channel_broadcaster *cb,
                                         int send_goaway,
                                         int force_disconnect) {
  size_t i;

  for (i = 0; i < cb->num_channels; i++) {
    send_shutdown(cb->channels[i], send_goaway, force_disconnect);
    GRPC_CHANNEL_INTERNAL_UNREF(cb->channels[i], "broadcast");
  }
  gpr_free(cb->channels);
}

/*
 * request_matcher
 */

static void request_matcher_init(request_matcher *request_matcher,
                                 int entries) {
  memset(request_matcher, 0, sizeof(*request_matcher));
  request_matcher->requests = gpr_stack_lockfree_create(entries);
}

static void request_matcher_destroy(request_matcher *request_matcher) {
  GPR_ASSERT(gpr_stack_lockfree_pop(request_matcher->requests) == -1);
  gpr_stack_lockfree_destroy(request_matcher->requests);
}

static void kill_zombie(void *elem, int success) {
  grpc_call_destroy(grpc_call_from_top_element(elem));
}

static void request_matcher_zombify_all_pending_calls(
    request_matcher *request_matcher) {
  while (request_matcher->pending_head) {
    call_data *calld = request_matcher->pending_head;
    request_matcher->pending_head = calld->pending_next;
    gpr_mu_lock(&calld->mu_state);
    calld->state = ZOMBIED;
    gpr_mu_unlock(&calld->mu_state);
    grpc_iomgr_closure_init(
        &calld->kill_zombie_closure, kill_zombie,
        grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0));
    grpc_iomgr_add_callback(&calld->kill_zombie_closure);
  }
}

static void request_matcher_kill_requests(grpc_server *server,
                                          request_matcher *rm) {
  int request_id;
  while ((request_id = gpr_stack_lockfree_pop(rm->requests)) != -1) {
    fail_call(server, &server->requested_calls[request_id]);
  }
}

/*
 * server proper
 */

static void server_ref(grpc_server *server) {
  gpr_ref(&server->internal_refcount);
}

static void server_delete(grpc_server *server) {
  registered_method *rm;
  size_t i;
  grpc_channel_args_destroy(server->channel_args);
  gpr_mu_destroy(&server->mu_global);
  gpr_mu_destroy(&server->mu_call);
  gpr_free(server->channel_filters);
  while ((rm = server->registered_methods) != NULL) {
    server->registered_methods = rm->next;
    request_matcher_destroy(&rm->request_matcher);
    gpr_free(rm->method);
    gpr_free(rm->host);
    gpr_free(rm);
  }
  for (i = 0; i < server->cq_count; i++) {
    GRPC_CQ_INTERNAL_UNREF(server->cqs[i], "server");
  }
  request_matcher_destroy(&server->unregistered_request_matcher);
  gpr_stack_lockfree_destroy(server->request_freelist);
  gpr_free(server->cqs);
  gpr_free(server->pollsets);
  gpr_free(server->shutdown_tags);
  gpr_free(server->requested_calls);
  gpr_free(server);
}

static void server_unref(grpc_server *server) {
  if (gpr_unref(&server->internal_refcount)) {
    server_delete(server);
  }
}

static int is_channel_orphaned(channel_data *chand) {
  return chand->next == chand;
}

static void orphan_channel(channel_data *chand) {
  chand->next->prev = chand->prev;
  chand->prev->next = chand->next;
  chand->next = chand->prev = chand;
}

static void finish_destroy_channel(void *cd, int success) {
  channel_data *chand = cd;
  grpc_server *server = chand->server;
  GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "server");
  server_unref(server);
}

static void destroy_channel(channel_data *chand) {
  if (is_channel_orphaned(chand)) return;
  GPR_ASSERT(chand->server != NULL);
  orphan_channel(chand);
  server_ref(chand->server);
  maybe_finish_shutdown(chand->server);
  chand->finish_destroy_channel_closure.cb = finish_destroy_channel;
  chand->finish_destroy_channel_closure.cb_arg = chand;
  grpc_iomgr_add_callback(&chand->finish_destroy_channel_closure);
}

static void finish_start_new_rpc(grpc_server *server, grpc_call_element *elem,
                                 request_matcher *request_matcher) {
  call_data *calld = elem->call_data;
  int request_id;

  if (gpr_atm_acq_load(&server->shutdown_flag)) {
    gpr_mu_lock(&calld->mu_state);
    calld->state = ZOMBIED;
    gpr_mu_unlock(&calld->mu_state);
    grpc_iomgr_closure_init(&calld->kill_zombie_closure, kill_zombie, elem);
    grpc_iomgr_add_callback(&calld->kill_zombie_closure);
    return;
  }

  request_id = gpr_stack_lockfree_pop(request_matcher->requests);
  if (request_id == -1) {
    gpr_mu_lock(&server->mu_call);
    gpr_mu_lock(&calld->mu_state);
    calld->state = PENDING;
    gpr_mu_unlock(&calld->mu_state);
    if (request_matcher->pending_head == NULL) {
      request_matcher->pending_tail = request_matcher->pending_head = calld;
    } else {
      request_matcher->pending_tail->pending_next = calld;
      request_matcher->pending_tail = calld;
    }
    calld->pending_next = NULL;
    gpr_mu_unlock(&server->mu_call);
  } else {
    gpr_mu_lock(&calld->mu_state);
    calld->state = ACTIVATED;
    gpr_mu_unlock(&calld->mu_state);
    begin_call(server, calld, &server->requested_calls[request_id]);
  }
}

static void start_new_rpc(grpc_call_element *elem) {
  channel_data *chand = elem->channel_data;
  call_data *calld = elem->call_data;
  grpc_server *server = chand->server;
  gpr_uint32 i;
  gpr_uint32 hash;
  channel_registered_method *rm;

  if (chand->registered_methods && calld->path && calld->host) {
    /* TODO(ctiller): unify these two searches */
    /* check for an exact match with host */
    hash = GRPC_MDSTR_KV_HASH(calld->host->hash, calld->path->hash);
    for (i = 0; i <= chand->registered_method_max_probes; i++) {
      rm = &chand->registered_methods[(hash + i) %
                                      chand->registered_method_slots];
      if (!rm) break;
      if (rm->host != calld->host) continue;
      if (rm->method != calld->path) continue;
      finish_start_new_rpc(server, elem,
                           &rm->server_registered_method->request_matcher);
      return;
    }
    /* check for a wildcard method definition (no host set) */
    hash = GRPC_MDSTR_KV_HASH(0, calld->path->hash);
    for (i = 0; i <= chand->registered_method_max_probes; i++) {
      rm = &chand->registered_methods[(hash + i) %
                                      chand->registered_method_slots];
      if (!rm) break;
      if (rm->host != NULL) continue;
      if (rm->method != calld->path) continue;
      finish_start_new_rpc(server, elem,
                           &rm->server_registered_method->request_matcher);
      return;
    }
  }
  finish_start_new_rpc(server, elem, &server->unregistered_request_matcher);
}

static int num_listeners(grpc_server *server) {
  listener *l;
  int n = 0;
  for (l = server->listeners; l; l = l->next) {
    n++;
  }
  return n;
}

static void done_shutdown_event(void *server, grpc_cq_completion *completion) {
  server_unref(server);
}

static int num_channels(grpc_server *server) {
  channel_data *chand;
  int n = 0;
  for (chand = server->root_channel_data.next;
       chand != &server->root_channel_data; chand = chand->next) {
    n++;
  }
  return n;
}

static void kill_pending_work_locked(grpc_server *server) {
  registered_method *rm;
  request_matcher_kill_requests(server, &server->unregistered_request_matcher);
  request_matcher_zombify_all_pending_calls(
      &server->unregistered_request_matcher);
  for (rm = server->registered_methods; rm; rm = rm->next) {
    request_matcher_kill_requests(server, &rm->request_matcher);
    request_matcher_zombify_all_pending_calls(&rm->request_matcher);
  }
}

static void maybe_finish_shutdown(grpc_server *server) {
  size_t i;
  if (!gpr_atm_acq_load(&server->shutdown_flag) || server->shutdown_published) {
    return;
  }

  kill_pending_work_locked(server);

  if (server->root_channel_data.next != &server->root_channel_data ||
      server->listeners_destroyed < num_listeners(server)) {
    if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME),
                                  server->last_shutdown_message_time),
                     gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) {
      server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
      gpr_log(GPR_DEBUG,
              "Waiting for %d channels and %d/%d listeners to be destroyed"
              " before shutting down server",
              num_channels(server),
              num_listeners(server) - server->listeners_destroyed,
              num_listeners(server));
    }
    return;
  }
  server->shutdown_published = 1;
  for (i = 0; i < server->num_shutdown_tags; i++) {
    server_ref(server);
    grpc_cq_end_op(server->shutdown_tags[i].cq, server->shutdown_tags[i].tag, 1,
                   done_shutdown_event, server,
                   &server->shutdown_tags[i].completion);
  }
}

static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) {
  grpc_call_element *elem = user_data;
  channel_data *chand = elem->channel_data;
  call_data *calld = elem->call_data;
  if (md->key == chand->path_key) {
    calld->path = GRPC_MDSTR_REF(md->value);
    return NULL;
  } else if (md->key == chand->authority_key) {
    calld->host = GRPC_MDSTR_REF(md->value);
    return NULL;
  }
  return md;
}

static void server_on_recv(void *ptr, int success) {
  grpc_call_element *elem = ptr;
  call_data *calld = elem->call_data;
  gpr_timespec op_deadline;

  if (success && !calld->got_initial_metadata) {
    size_t i;
    size_t nops = calld->recv_ops->nops;
    grpc_stream_op *ops = calld->recv_ops->ops;
    for (i = 0; i < nops; i++) {
      grpc_stream_op *op = &ops[i];
      if (op->type != GRPC_OP_METADATA) continue;
      grpc_metadata_batch_filter(&op->data.metadata, server_filter, elem);
      op_deadline = op->data.metadata.deadline;
      if (0 !=
          gpr_time_cmp(op_deadline, gpr_inf_future(op_deadline.clock_type))) {
        calld->deadline = op->data.metadata.deadline;
      }
      if (calld->host && calld->path) {
        calld->got_initial_metadata = 1;
        start_new_rpc(elem);
      }
      break;
    }
  }

  switch (*calld->recv_state) {
    case GRPC_STREAM_OPEN:
      break;
    case GRPC_STREAM_SEND_CLOSED:
      break;
    case GRPC_STREAM_RECV_CLOSED:
      gpr_mu_lock(&calld->mu_state);
      if (calld->state == NOT_STARTED) {
        calld->state = ZOMBIED;
        gpr_mu_unlock(&calld->mu_state);
        grpc_iomgr_closure_init(&calld->kill_zombie_closure, kill_zombie, elem);
        grpc_iomgr_add_callback(&calld->kill_zombie_closure);
      } else {
        gpr_mu_unlock(&calld->mu_state);
      }
      break;
    case GRPC_STREAM_CLOSED:
      gpr_mu_lock(&calld->mu_state);
      if (calld->state == NOT_STARTED) {
        calld->state = ZOMBIED;
        gpr_mu_unlock(&calld->mu_state);
        grpc_iomgr_closure_init(&calld->kill_zombie_closure, kill_zombie, elem);
        grpc_iomgr_add_callback(&calld->kill_zombie_closure);
      } else if (calld->state == PENDING) {
        calld->state = ZOMBIED;
        gpr_mu_unlock(&calld->mu_state);
        /* zombied call will be destroyed when it's removed from the pending
           queue... later */
      } else {
        gpr_mu_unlock(&calld->mu_state);
      }
      break;
  }

  calld->on_done_recv->cb(calld->on_done_recv->cb_arg, success);
}

static void server_mutate_op(grpc_call_element *elem,
                             grpc_transport_stream_op *op) {
  call_data *calld = elem->call_data;

  if (op->recv_ops) {
    /* substitute our callback for the higher callback */
    calld->recv_ops = op->recv_ops;
    calld->recv_state = op->recv_state;
    calld->on_done_recv = op->on_done_recv;
    op->on_done_recv = &calld->server_on_recv;
  }
}

static void server_start_transport_stream_op(grpc_call_element *elem,
                                             grpc_transport_stream_op *op) {
  GRPC_CALL_LOG_OP(GPR_INFO, elem, op);
  server_mutate_op(elem, op);
  grpc_call_next_op(elem, op);
}

static void accept_stream(void *cd, grpc_transport *transport,
                          const void *transport_server_data) {
  channel_data *chand = cd;
  /* create a call */
  grpc_call_create(chand->channel, NULL, 0, NULL, transport_server_data, NULL,
                   0, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}

static void channel_connectivity_changed(void *cd, int iomgr_status_ignored) {
  channel_data *chand = cd;
  grpc_server *server = chand->server;
  if (chand->connectivity_state != GRPC_CHANNEL_FATAL_FAILURE) {
    grpc_transport_op op;
    memset(&op, 0, sizeof(op));
    op.on_connectivity_state_change = &chand->channel_connectivity_changed,
    op.connectivity_state = &chand->connectivity_state;
    grpc_channel_next_op(grpc_channel_stack_element(
                             grpc_channel_get_channel_stack(chand->channel), 0),
                         &op);
  } else {
    gpr_mu_lock(&server->mu_global);
    destroy_channel(chand);
    gpr_mu_unlock(&server->mu_global);
    GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "connectivity");
  }
}

static void init_call_elem(grpc_call_element *elem,
                           const void *server_transport_data,
                           grpc_transport_stream_op *initial_op) {
  call_data *calld = elem->call_data;
  channel_data *chand = elem->channel_data;
  memset(calld, 0, sizeof(call_data));
  calld->deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
  calld->call = grpc_call_from_top_element(elem);
  gpr_mu_init(&calld->mu_state);

  grpc_iomgr_closure_init(&calld->server_on_recv, server_on_recv, elem);

  server_ref(chand->server);

  if (initial_op) server_mutate_op(elem, initial_op);
}

static void destroy_call_elem(grpc_call_element *elem) {
  channel_data *chand = elem->channel_data;
  call_data *calld = elem->call_data;

  GPR_ASSERT(calld->state != PENDING);

  if (calld->host) {
    GRPC_MDSTR_UNREF(calld->host);
  }
  if (calld->path) {
    GRPC_MDSTR_UNREF(calld->path);
  }

  gpr_mu_destroy(&calld->mu_state);

  server_unref(chand->server);
}

static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
                              const grpc_channel_args *args,
                              grpc_mdctx *metadata_context, int is_first,
                              int is_last) {
  channel_data *chand = elem->channel_data;
  GPR_ASSERT(is_first);
  GPR_ASSERT(!is_last);
  chand->server = NULL;
  chand->channel = NULL;
  chand->path_key = grpc_mdstr_from_string(metadata_context, ":path", 0);
  chand->authority_key =
      grpc_mdstr_from_string(metadata_context, ":authority", 0);
  chand->next = chand->prev = chand;
  chand->registered_methods = NULL;
  chand->connectivity_state = GRPC_CHANNEL_IDLE;
  grpc_iomgr_closure_init(&chand->channel_connectivity_changed,
                          channel_connectivity_changed, chand);
}

static void destroy_channel_elem(grpc_channel_element *elem) {
  size_t i;
  channel_data *chand = elem->channel_data;
  if (chand->registered_methods) {
    for (i = 0; i < chand->registered_method_slots; i++) {
      if (chand->registered_methods[i].method) {
        GRPC_MDSTR_UNREF(chand->registered_methods[i].method);
      }
      if (chand->registered_methods[i].host) {
        GRPC_MDSTR_UNREF(chand->registered_methods[i].host);
      }
    }
    gpr_free(chand->registered_methods);
  }
  if (chand->server) {
    gpr_mu_lock(&chand->server->mu_global);
    chand->next->prev = chand->prev;
    chand->prev->next = chand->next;
    chand->next = chand->prev = chand;
    maybe_finish_shutdown(chand->server);
    gpr_mu_unlock(&chand->server->mu_global);
    GRPC_MDSTR_UNREF(chand->path_key);
    GRPC_MDSTR_UNREF(chand->authority_key);
    server_unref(chand->server);
  }
}

static const grpc_channel_filter server_surface_filter = {
    server_start_transport_stream_op,
    grpc_channel_next_op,
    sizeof(call_data),
    init_call_elem,
    destroy_call_elem,
    sizeof(channel_data),
    init_channel_elem,
    destroy_channel_elem,
    grpc_call_next_get_peer,
    "server",
};

void grpc_server_register_completion_queue(grpc_server *server,
                                           grpc_completion_queue *cq,
                                           void *reserved) {
  size_t i, n;
  GPR_ASSERT(!reserved);
  for (i = 0; i < server->cq_count; i++) {
    if (server->cqs[i] == cq) return;
  }
  GRPC_CQ_INTERNAL_REF(cq, "server");
  grpc_cq_mark_server_cq(cq);
  n = server->cq_count++;
  server->cqs = gpr_realloc(server->cqs,
                            server->cq_count * sizeof(grpc_completion_queue *));
  server->cqs[n] = cq;
}

grpc_server *grpc_server_create_from_filters(
    const grpc_channel_filter **filters, size_t filter_count,
    const grpc_channel_args *args) {
  size_t i;
  /* TODO(census): restore this once we finalize census filter etc.
     int census_enabled = grpc_channel_args_is_census_enabled(args); */
  int census_enabled = 0;

  grpc_server *server = gpr_malloc(sizeof(grpc_server));

  GPR_ASSERT(grpc_is_initialized() && "call grpc_init()");

  memset(server, 0, sizeof(grpc_server));

  gpr_mu_init(&server->mu_global);
  gpr_mu_init(&server->mu_call);

  /* decremented by grpc_server_destroy */
  gpr_ref_init(&server->internal_refcount, 1);
  server->root_channel_data.next = server->root_channel_data.prev =
      &server->root_channel_data;

  /* TODO(ctiller): expose a channel_arg for this */
  server->max_requested_calls = 32768;
  server->request_freelist =
      gpr_stack_lockfree_create(server->max_requested_calls);
  for (i = 0; i < (size_t)server->max_requested_calls; i++) {
    gpr_stack_lockfree_push(server->request_freelist, i);
  }
  request_matcher_init(&server->unregistered_request_matcher,
                       server->max_requested_calls);
  server->requested_calls = gpr_malloc(server->max_requested_calls *
                                       sizeof(*server->requested_calls));

  /* Server filter stack is:

     server_surface_filter - for making surface API calls
     grpc_server_census_filter (optional) - for stats collection and tracing
     {passed in filter stack}
     grpc_connected_channel_filter - for interfacing with transports */
  server->channel_filter_count = filter_count + 1 + census_enabled;
  server->channel_filters =
      gpr_malloc(server->channel_filter_count * sizeof(grpc_channel_filter *));
  server->channel_filters[0] = &server_surface_filter;
  /* TODO(census): restore this once we rework census filter
  if (census_enabled) {
    server->channel_filters[1] = &grpc_server_census_filter;
    } */
  for (i = 0; i < filter_count; i++) {
    server->channel_filters[i + 1 + census_enabled] = filters[i];
  }

  server->channel_args = grpc_channel_args_copy(args);

  return server;
}

static int streq(const char *a, const char *b) {
  if (a == NULL && b == NULL) return 1;
  if (a == NULL) return 0;
  if (b == NULL) return 0;
  return 0 == strcmp(a, b);
}

void *grpc_server_register_method(grpc_server *server, const char *method,
                                  const char *host) {
  registered_method *m;
  if (!method) {
    gpr_log(GPR_ERROR,
            "grpc_server_register_method method string cannot be NULL");
    return NULL;
  }
  for (m = server->registered_methods; m; m = m->next) {
    if (streq(m->method, method) && streq(m->host, host)) {
      gpr_log(GPR_ERROR, "duplicate registration for %s@%s", method,
              host ? host : "*");
      return NULL;
    }
  }
  m = gpr_malloc(sizeof(registered_method));
  memset(m, 0, sizeof(*m));
  request_matcher_init(&m->request_matcher, server->max_requested_calls);
  m->method = gpr_strdup(method);
  m->host = gpr_strdup(host);
  m->next = server->registered_methods;
  server->registered_methods = m;
  return m;
}

void grpc_server_start(grpc_server *server) {
  listener *l;
  size_t i;

  server->pollsets = gpr_malloc(sizeof(grpc_pollset *) * server->cq_count);
  for (i = 0; i < server->cq_count; i++) {
    server->pollsets[i] = grpc_cq_pollset(server->cqs[i]);
  }

  for (l = server->listeners; l; l = l->next) {
    l->start(server, l->arg, server->pollsets, server->cq_count);
  }
}

void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport,
                                 grpc_channel_filter const **extra_filters,
                                 size_t num_extra_filters, grpc_mdctx *mdctx,
                                 const grpc_channel_args *args) {
  size_t num_filters = s->channel_filter_count + num_extra_filters + 1;
  grpc_channel_filter const **filters =
      gpr_malloc(sizeof(grpc_channel_filter *) * num_filters);
  size_t i;
  size_t num_registered_methods;
  size_t alloc;
  registered_method *rm;
  channel_registered_method *crm;
  grpc_channel *channel;
  channel_data *chand;
  grpc_mdstr *host;
  grpc_mdstr *method;
  gpr_uint32 hash;
  gpr_uint32 slots;
  gpr_uint32 probes;
  gpr_uint32 max_probes = 0;
  grpc_transport_op op;

  for (i = 0; i < s->channel_filter_count; i++) {
    filters[i] = s->channel_filters[i];
  }
  for (; i < s->channel_filter_count + num_extra_filters; i++) {
    filters[i] = extra_filters[i - s->channel_filter_count];
  }
  filters[i] = &grpc_connected_channel_filter;

  for (i = 0; i < s->cq_count; i++) {
    memset(&op, 0, sizeof(op));
    op.bind_pollset = grpc_cq_pollset(s->cqs[i]);
    grpc_transport_perform_op(transport, &op);
  }

  channel = grpc_channel_create_from_filters(NULL, filters, num_filters, args,
                                             mdctx, 0);
  chand = (channel_data *)grpc_channel_stack_element(
              grpc_channel_get_channel_stack(channel), 0)
              ->channel_data;
  chand->server = s;
  server_ref(s);
  chand->channel = channel;

  num_registered_methods = 0;
  for (rm = s->registered_methods; rm; rm = rm->next) {
    num_registered_methods++;
  }
  /* build a lookup table phrased in terms of mdstr's in this channels context
     to quickly find registered methods */
  if (num_registered_methods > 0) {
    slots = 2 * num_registered_methods;
    alloc = sizeof(channel_registered_method) * slots;
    chand->registered_methods = gpr_malloc(alloc);
    memset(chand->registered_methods, 0, alloc);
    for (rm = s->registered_methods; rm; rm = rm->next) {
      host = rm->host ? grpc_mdstr_from_string(mdctx, rm->host, 0) : NULL;
      method = grpc_mdstr_from_string(mdctx, rm->method, 0);
      hash = GRPC_MDSTR_KV_HASH(host ? host->hash : 0, method->hash);
      for (probes = 0; chand->registered_methods[(hash + probes) % slots]
                           .server_registered_method != NULL;
           probes++)
        ;
      if (probes > max_probes) max_probes = probes;
      crm = &chand->registered_methods[(hash + probes) % slots];
      crm->server_registered_method = rm;
      crm->host = host;
      crm->method = method;
    }
    chand->registered_method_slots = slots;
    chand->registered_method_max_probes = max_probes;
  }

  grpc_connected_channel_bind_transport(grpc_channel_get_channel_stack(channel),
                                        transport);

  gpr_mu_lock(&s->mu_global);
  chand->next = &s->root_channel_data;
  chand->prev = chand->next->prev;
  chand->next->prev = chand->prev->next = chand;
  gpr_mu_unlock(&s->mu_global);

  gpr_free(filters);

  GRPC_CHANNEL_INTERNAL_REF(channel, "connectivity");
  memset(&op, 0, sizeof(op));
  op.set_accept_stream = accept_stream;
  op.set_accept_stream_user_data = chand;
  op.on_connectivity_state_change = &chand->channel_connectivity_changed;
  op.connectivity_state = &chand->connectivity_state;
  op.disconnect = gpr_atm_acq_load(&s->shutdown_flag);
  grpc_transport_perform_op(transport, &op);
}

void grpc_server_shutdown_and_notify(grpc_server *server,
                                     grpc_completion_queue *cq, void *tag) {
  listener *l;
  shutdown_tag *sdt;
  channel_broadcaster broadcaster;

  GRPC_SERVER_LOG_SHUTDOWN(GPR_INFO, server, cq, tag);

  /* lock, and gather up some stuff to do */
  gpr_mu_lock(&server->mu_global);
  grpc_cq_begin_op(cq);
  server->shutdown_tags =
      gpr_realloc(server->shutdown_tags,
                  sizeof(shutdown_tag) * (server->num_shutdown_tags + 1));
  sdt = &server->shutdown_tags[server->num_shutdown_tags++];
  sdt->tag = tag;
  sdt->cq = cq;
  if (gpr_atm_acq_load(&server->shutdown_flag)) {
    gpr_mu_unlock(&server->mu_global);
    return;
  }

  server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);

  channel_broadcaster_init(server, &broadcaster);

  /* collect all unregistered then registered calls */
  gpr_mu_lock(&server->mu_call);
  kill_pending_work_locked(server);
  gpr_mu_unlock(&server->mu_call);

  gpr_atm_rel_store(&server->shutdown_flag, 1);
  maybe_finish_shutdown(server);
  gpr_mu_unlock(&server->mu_global);

  /* Shutdown listeners */
  for (l = server->listeners; l; l = l->next) {
    l->destroy(server, l->arg);
  }

  channel_broadcaster_shutdown(&broadcaster, 1, 0);
}

void grpc_server_listener_destroy_done(void *s) {
  grpc_server *server = s;
  gpr_mu_lock(&server->mu_global);
  server->listeners_destroyed++;
  maybe_finish_shutdown(server);
  gpr_mu_unlock(&server->mu_global);
}

void grpc_server_cancel_all_calls(grpc_server *server) {
  channel_broadcaster broadcaster;

  gpr_mu_lock(&server->mu_global);
  channel_broadcaster_init(server, &broadcaster);
  gpr_mu_unlock(&server->mu_global);

  channel_broadcaster_shutdown(&broadcaster, 0, 1);
}

void grpc_server_destroy(grpc_server *server) {
  listener *l;

  gpr_mu_lock(&server->mu_global);
  GPR_ASSERT(gpr_atm_acq_load(&server->shutdown_flag) || !server->listeners);
  GPR_ASSERT(server->listeners_destroyed == num_listeners(server));

  while (server->listeners) {
    l = server->listeners;
    server->listeners = l->next;
    gpr_free(l);
  }

  gpr_mu_unlock(&server->mu_global);

  server_unref(server);
}

void grpc_server_add_listener(grpc_server *server, void *arg,
                              void (*start)(grpc_server *server, void *arg,
                                            grpc_pollset **pollsets,
                                            size_t pollset_count),
                              void (*destroy)(grpc_server *server, void *arg)) {
  listener *l = gpr_malloc(sizeof(listener));
  l->arg = arg;
  l->start = start;
  l->destroy = destroy;
  l->next = server->listeners;
  server->listeners = l;
}

static grpc_call_error queue_call_request(grpc_server *server,
                                          requested_call *rc) {
  call_data *calld = NULL;
  request_matcher *request_matcher = NULL;
  int request_id;
  if (gpr_atm_acq_load(&server->shutdown_flag)) {
    fail_call(server, rc);
    return GRPC_CALL_OK;
  }
  request_id = gpr_stack_lockfree_pop(server->request_freelist);
  if (request_id == -1) {
    /* out of request ids: just fail this one */
    fail_call(server, rc);
    return GRPC_CALL_OK;
  }
  switch (rc->type) {
    case BATCH_CALL:
      request_matcher = &server->unregistered_request_matcher;
      break;
    case REGISTERED_CALL:
      request_matcher = &rc->data.registered.registered_method->request_matcher;
      break;
  }
  server->requested_calls[request_id] = *rc;
  gpr_free(rc);
  if (gpr_stack_lockfree_push(request_matcher->requests, request_id)) {
    /* this was the first queued request: we need to lock and start
       matching calls */
    gpr_mu_lock(&server->mu_call);
    while ((calld = request_matcher->pending_head) != NULL) {
      request_id = gpr_stack_lockfree_pop(request_matcher->requests);
      if (request_id == -1) break;
      request_matcher->pending_head = calld->pending_next;
      gpr_mu_unlock(&server->mu_call);
      gpr_mu_lock(&calld->mu_state);
      if (calld->state == ZOMBIED) {
        gpr_mu_unlock(&calld->mu_state);
        grpc_iomgr_closure_init(
            &calld->kill_zombie_closure, kill_zombie,
            grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0));
        grpc_iomgr_add_callback(&calld->kill_zombie_closure);
      } else {
        GPR_ASSERT(calld->state == PENDING);
        calld->state = ACTIVATED;
        gpr_mu_unlock(&calld->mu_state);
        begin_call(server, calld, &server->requested_calls[request_id]);
      }
      gpr_mu_lock(&server->mu_call);
    }
    gpr_mu_unlock(&server->mu_call);
  }
  return GRPC_CALL_OK;
}

grpc_call_error grpc_server_request_call(
    grpc_server *server, grpc_call **call, grpc_call_details *details,
    grpc_metadata_array *initial_metadata,
    grpc_completion_queue *cq_bound_to_call,
    grpc_completion_queue *cq_for_notification, void *tag) {
  requested_call *rc = gpr_malloc(sizeof(*rc));
  GRPC_SERVER_LOG_REQUEST_CALL(GPR_INFO, server, call, details,
                               initial_metadata, cq_bound_to_call,
                               cq_for_notification, tag);
  if (!grpc_cq_is_server_cq(cq_for_notification)) {
    gpr_free(rc);
    return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE;
  }
  grpc_cq_begin_op(cq_for_notification);
  rc->type = BATCH_CALL;
  rc->server = server;
  rc->tag = tag;
  rc->cq_bound_to_call = cq_bound_to_call;
  rc->cq_for_notification = cq_for_notification;
  rc->call = call;
  rc->data.batch.details = details;
  rc->data.batch.initial_metadata = initial_metadata;
  return queue_call_request(server, rc);
}

grpc_call_error grpc_server_request_registered_call(
    grpc_server *server, void *rm, grpc_call **call, gpr_timespec *deadline,
    grpc_metadata_array *initial_metadata, grpc_byte_buffer **optional_payload,
    grpc_completion_queue *cq_bound_to_call,
    grpc_completion_queue *cq_for_notification, void *tag) {
  requested_call *rc = gpr_malloc(sizeof(*rc));
  registered_method *registered_method = rm;
  if (!grpc_cq_is_server_cq(cq_for_notification)) {
    gpr_free(rc);
    return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE;
  }
  grpc_cq_begin_op(cq_for_notification);
  rc->type = REGISTERED_CALL;
  rc->server = server;
  rc->tag = tag;
  rc->cq_bound_to_call = cq_bound_to_call;
  rc->cq_for_notification = cq_for_notification;
  rc->call = call;
  rc->data.registered.registered_method = registered_method;
  rc->data.registered.deadline = deadline;
  rc->data.registered.initial_metadata = initial_metadata;
  rc->data.registered.optional_payload = optional_payload;
  return queue_call_request(server, rc);
}

static void publish_registered_or_batch(grpc_call *call, int success,
                                        void *tag);
static void publish_was_not_set(grpc_call *call, int success, void *tag) {
  abort();
}

static void cpstr(char **dest, size_t *capacity, grpc_mdstr *value) {
  gpr_slice slice = value->slice;
  size_t len = GPR_SLICE_LENGTH(slice);

  if (len + 1 > *capacity) {
    *capacity = GPR_MAX(len + 1, *capacity * 2);
    *dest = gpr_realloc(*dest, *capacity);
  }
  memcpy(*dest, grpc_mdstr_as_c_string(value), len + 1);
}

static void begin_call(grpc_server *server, call_data *calld,
                       requested_call *rc) {
  grpc_ioreq_completion_func publish = publish_was_not_set;
  grpc_ioreq req[2];
  grpc_ioreq *r = req;

  /* called once initial metadata has been read by the call, but BEFORE
     the ioreq to fetch it out of the call has been executed.
     This means metadata related fields can be relied on in calld, but to
     fill in the metadata array passed by the client, we need to perform
     an ioreq op, that should complete immediately. */

  grpc_call_set_completion_queue(calld->call, rc->cq_bound_to_call);
  *rc->call = calld->call;
  calld->cq_new = rc->cq_for_notification;
  switch (rc->type) {
    case BATCH_CALL:
      GPR_ASSERT(calld->host != NULL);
      GPR_ASSERT(calld->path != NULL);
      cpstr(&rc->data.batch.details->host,
            &rc->data.batch.details->host_capacity, calld->host);
      cpstr(&rc->data.batch.details->method,
            &rc->data.batch.details->method_capacity, calld->path);
      rc->data.batch.details->deadline = calld->deadline;
      r->op = GRPC_IOREQ_RECV_INITIAL_METADATA;
      r->data.recv_metadata = rc->data.batch.initial_metadata;
      r->flags = 0;
      r++;
      publish = publish_registered_or_batch;
      break;
    case REGISTERED_CALL:
      *rc->data.registered.deadline = calld->deadline;
      r->op = GRPC_IOREQ_RECV_INITIAL_METADATA;
      r->data.recv_metadata = rc->data.registered.initial_metadata;
      r->flags = 0;
      r++;
      if (rc->data.registered.optional_payload) {
        r->op = GRPC_IOREQ_RECV_MESSAGE;
        r->data.recv_message = rc->data.registered.optional_payload;
        r->flags = 0;
        r++;
      }
      publish = publish_registered_or_batch;
      break;
  }

  GRPC_CALL_INTERNAL_REF(calld->call, "server");
  grpc_call_start_ioreq_and_call_back(calld->call, req, r - req, publish, rc);
}

static void done_request_event(void *req, grpc_cq_completion *c) {
  requested_call *rc = req;
  grpc_server *server = rc->server;

  if (rc >= server->requested_calls &&
      rc < server->requested_calls + server->max_requested_calls) {
    gpr_stack_lockfree_push(server->request_freelist,
                            rc - server->requested_calls);
  } else {
    gpr_free(req);
  }

  server_unref(server);
}

static void fail_call(grpc_server *server, requested_call *rc) {
  *rc->call = NULL;
  switch (rc->type) {
    case BATCH_CALL:
      rc->data.batch.initial_metadata->count = 0;
      break;
    case REGISTERED_CALL:
      rc->data.registered.initial_metadata->count = 0;
      break;
  }
  server_ref(server);
  grpc_cq_end_op(rc->cq_for_notification, rc->tag, 0, done_request_event, rc,
                 &rc->completion);
}

static void publish_registered_or_batch(grpc_call *call, int success,
                                        void *prc) {
  grpc_call_element *elem =
      grpc_call_stack_element(grpc_call_get_call_stack(call), 0);
  requested_call *rc = prc;
  call_data *calld = elem->call_data;
  channel_data *chand = elem->channel_data;
  server_ref(chand->server);
  grpc_cq_end_op(calld->cq_new, rc->tag, success, done_request_event, rc,
                 &rc->completion);
  GRPC_CALL_INTERNAL_UNREF(call, "server", 0);
}

const grpc_channel_args *grpc_server_get_channel_args(grpc_server *server) {
  return server->channel_args;
}

int grpc_server_has_open_connections(grpc_server *server) {
  int r;
  gpr_mu_lock(&server->mu_global);
  r = server->root_channel_data.next != &server->root_channel_data;
  gpr_mu_unlock(&server->mu_global);
  return r;
}

redpajama_set_name: RedPajamaGithub


text:
With over three decades in the region, Paul, Weiss has long been recognized as a leader and legal innovator among international law firms in Asia. Our Asia based partners have been consistently ranked in the top tier of practitioners in their areas of expertise.
From our three offices in Beijing, Hong Kong and Tokyo, we handle a wide range of complex transactional matters across all of Asia, particularly in mainland China, Hong Kong, Taiwan and Japan. We act for some of the well-known companies in the technology, media, entertainment, telecommunications, banking, insurance and asset management industries, as well as many prominent entities across many other fields. We also advise many of our clients in Asia on sensitive U.S. regulatory and litigation matters, drawing seamlessly on the expertise of our world-renowned Litigation Department.
Our experienced multilingual and multicultural team understands the host of challenges that arise from differences in legal systems, cultures, languages, business practices and perspectives, ensuring that all angles are covered.
Paul, Weiss has one of the most dynamic China practices among international law firms, consistently earning us top-tier recognition in publications such as Chambers, The Legal 500, IFLR1000, Asian Lawyer, China Business Law Journal and Asian Legal Business. We first established our presence in Beijing in 1981 and thus have the longest continuous presence of any foreign law firm in mainland China. In 1983, we established a Hong Kong limited liability partnership, and in 1998, Paul, Weiss was qualified and registered as a Hong Kong law firm, enabling us to advise on Hong Kong law matters.
Our multinational team of Western-trained, Chinese-speaking lawyers has a deep understanding of the Chinese legal system and international business transactions. Known as practical and creative problem solvers, we handle matters involving mergers and acquisitions, private equity and venture capital, outbound investments, foreign direct investments, capital markets, corporate and project finance, joint ventures, restructuring and internal investigations, including investigations under the U.S. Foreign Corrupt Practices Act (FCPA). We have played a role in a number of precedent-setting transactions in mainland China, including one of the largest-ever buyouts in China; one of the largest-ever private financings of a Chinese company; and several ground-breaking media, theme parks, gaming and other joint ventures with iconic U.S. entertainment, gaming and media companies.
High-profile private equity practice with an enviable portfolio of work and clients, featuring mandates from major U.S. investment houses. Well known for its significant track record advising on foreign direct investment. Also offers broad public M&A expertise, centered on high-profile TMT-related investment.
– Chambers Asia Pacific 2018
With 30 years of experience on the ground in Tokyo, we are a leader among U.S. law firms representing Japanese corporations and other Japanese institutions in cross-border transactions and in representing U.S. and other non-Japanese clients in connection with their activities in Japan. Our bilingual, bicultural Tokyo-based team is widely recognized for the excellence of its cross-border M&A practice in Japan and its work advising Japanese companies issuing securities in the U.S. and other global markets. We also have deep expertise in investment fund formations and cross-border restructurings. We have been involved in a number of landmark corporate matters, including the largest-ever acquisition of a Japanese company by a non-Japanese firm; the first tender offer in Japan for a JREIT; one of the largest mergers in Japanese history forming one of the biggest global financial institutions; and the first "PIPE" (private investment in public equity) transaction in Japan by a private equity investor.
At a time of heightened regulatory enforcement globally, we also regularly advise a growing number of Japanese clients, including executives and boards, on their most sensitive U.S. regulatory and litigation needs. This practice draws on a core team of U.S. litigators, including former high-ranking government regulators and lawyers with particular experience with Japanese clients. We work on (FCPA) and other anti-corruption matters; antitrust and cartel challenges; private commercial and class litigation and dispute resolution matters; and internal investigations.
Paul, Weiss, Rifkind, Wharton & Garrison is strong in M&A and capital markets in Japan - especially in capital markets where it is ranked highest...
– IFLR1000 2018
Paul, Weiss has been involved in Taiwan-related investments since the early 1980s. In the early 1990s, we assisted Verizon (formerly GTE) in its auction for the first-ever mobile telecommunications license issued in Taiwan and participated in the ground-breaking investment by Verizon in Taiwan. We also played a significant role in the creation of the first ever MSOs in Taiwan. The MSO model was soon followed by other investors in the cable system sector. We have also been involved in many of the leading private equity investments in Taiwan today. We have since established a solid track record representing Taiwanese and international clients in corporate transactional matters involving private equity and venture capital, mergers and acquisitions, foreign direct investments, capital markets, corporate and project finance and restructurings.
Our practice has played a key role in a number of precedent-setting transactions in Taiwan, including one of the largest M&A deals to have ever occurred in Taiwan; one of the largest-ever buyouts; the first-ever foreign private equity sponsored buyout of a listed company; and several other ground-breaking transactions with leading U.S. private equity firms.
Offers broad public M&A expertise, centered on high-profile TMT-related investment, with notable experience advising on matters related to Taiwan.
Paul, Weiss has spent years cultivating a vibrant practice in Korea. Our recent work has included acquisitions and the formation of new joint ventures involving Korean companies, and investments by multinationals in Korean enterprises. We also represent Korean companies in their transactions outside of Korea, and understand the nuances of working with these dynamic companies.
We have also represented Korean enterprises and individual executives in complex litigations and regulatory defense matters. More than 20 Korean-speaking lawyers across the firm are able to assist Korean clients on various aspects of any matter, including our anti-corruption and FCPA Practice Group co-chair, and a native Korean partner who is based in our Tokyo office.
Betty Yap Gives Keynote Speech at the EY Professional Women's Network Launch Ceremony
Corporate partner Betty Yap was invited to be a keynote speaker at the Launching Ceremony of the 2021 EY Professional Women's Network Mentorship Program.
Update for Chinese SEC Reporting Companies: President's Working Group Issues Mandated Report on Listings
On August 6, the President's Working Group on Financial Markets released its report in response to President Trump's mandate that it set forth recommendations to address the continued constraints on access by the Public Company…
Paul, Weiss Panel: Recent Development in the U.S. Affecting U.S.-Listed Chinese Companies
Paul, Weiss will host a webinar presentation, "Recent Developments in the United States Affecting U.S.-Listed Chinese Companies," featuring corporate partners Mark Bergman and Xiaoyu Greg Liu, and litigation partners Christopher…
Update for Chinese SEC Reporting Companies: President Trump Mandates Report on PCAOB Access and Investor Protections
In response to the political impasse over access by U.S. regulators to information relating to U.S.-listed Chinese companies and, in particular, access by the Public Company Accounting Oversight Board to work papers relating to the…
Disclosure and Other Considerations: an Update for Chinese SEC Reporting Companies
As many Chinese companies with SEC reporting obligations have taken advantage of the relief provided by the U.S. Securities and Exchange Commission to delay the filings of their annual reports on Form 20-F, we outline key disclosure…
U.S. State Department Issues Unprecedented Global Travel Advisory
The State Department has issued a Level 4 (Do Not Travel) advisory for all travel outside the United States. It advises U.S. citizens not to travel abroad and U.S. citizens abroad who reside in the United States to return home if…
Force Majeure in the Wake of the Coronavirus (COVID-19)
The coming months are likely to bring many assertions of force majeure—contract provisions that excuse a party's nonperformance when "acts of God" or other extraordinary events prevent a party from fulfilling its contractual…
Does President Trump Have Authority to Force U.S. Companies to Leave China?
On August 23, 2019, President Trump tweeted that "American companies are hereby ordered to immediately start looking for an alternative to China, including bringing. . .your companies [home] and making products in the USA." In further …
China Issues Market-Entry Negative List And Publishes Draft Foreign Investment Law for Public Comment
Since late 2017, in the context of the escalating trade war between the United States and Chinese governments, Chinese political leaders have signaled that they are willing to address some of the issues that the U.S. and other…
Hans-Günther Herrmann Speaks on Foreign Investment in China
Corporate counsel Hans-Günther Herrmann gave a seminar to the French Chamber of Commerce and Industry in Hong Kong entitled "Foreign Investment in China in the time of the Trade War."
Paul, Weiss in Beijing: A New Chapter
In August 2018, Paul, Weiss's Beijing office moved to Fortune Financial Center, the second-tallest office tower in the metropolis. The firm's relocation provided an opportunity to reflect on the office's storied history and future…
Marking Thirty Years in Tokyo
In October 2017, Paul, Weiss celebrated the 30th anniversary of its Tokyo office with a Tokyo reception for clients and friends of the firm and a separate dinner with our alumni in Japan.
Jack Lange Interviewed By Bloomberg
Corporate partner Jack Lange was interviewed by Bloomberg Markets in Hong Kong about the impact of the U.S. Administration on businesses in Asia.
Secretary Johnson Speaks at AmCham Hong Kong
Litigation partner Jeh Johnson was the keynote speaker at a luncheon at the American Chamber of Commerce (AmCham) in Hong Kong.
China's Insurance Regulator Issues Revised Draft Measures for the Administration of Equity Interests
In December 2016, the China Insurance Company Regulatory Commission (CIRC) released draft measures for the administration of equity interests in insurance companies, as we noted in previous updates here and here. On July 20, CIRC…
Jack Lange Hosts AmCham Reception Celebrating 20th Anniversary of Hong Kong
Hong Kong-based partner Jack Lange, in his capacity as Vice Chairman of the American Chamber of Commerce in Hong Kong, hosted an AmCham reception celebrating the 20th anniversary of the establishment of the Hong Kong Special…
Betty Yap to Moderate Panel at IFLR Asia Women in Business Law Forum
Corporate partner Betty Yap will moderate a panel at the International Financial Law Review's Asia Women in Business Law Forum.
Judie Ng Shortell to Speak at Private Equity & Venture Forum in Beijing
Corporate partner Judie Ng Shortell will take part in the Asian Venture Capital Journal's annual China Private Equity & Venture Forum.
Client Alert: Draft Regulations Set to Change Landscape of Investments in Chinese Insurance Companies
On December 29, the China Insurance Regulatory Commission released draft measures for the Administration of Equity Interests in Insurance Companies. The measures, expected to be finalized and implemented soon, will affect future…
Hans-Günther Herrmann and Jack Sun Co-Author Article on China's FIE Reform, China Law & Practice
Corporate counsel Hans-Günther Herrmann and associate Jack Sun co-authored an article in the November/December issue of China Law & Practice.
Paul, Weiss Sponsors 30% Club Boardroom Lunch in Hong Kong
Paul, Weiss was a sponsor of the 30% Club's Annual Boardroom Lunch in Hong Kong. The lunch brought together an extensive and growing pool of accomplished and aspiring women directors with chairmen, board members and senior…
Christopher Frey to Address FCPA Compliance at ALB Corporate Forum in Japan
Litigation counsel Christopher Frey will participate in a panel discussion, titled "Ensuring FCPA Compliance in the APAC Region," at Asian Legal Business' upcoming Japan Corporate Compliance and Governance Forum.
Paul, Weiss Supports Launch of Women in Law Hong Kong's Pilot Mentoring Program
Women In Law Hong Kong (WILHK), hosted a launch event of the first cross-firm mentoring program for legal professionals as part of its commitment to enhancing the profiles, skills and networking opportunities available to women in the …
Jack Lange and Greg Liu to Speak at Private Equity & Venture Forum in Beijing
Corporate partners Jack Lange and Greg Liu took part in the Asian Venture Capital Journal's annual Private Equity & Venture Forum in Beijing.
Paul, Weiss Supports International Women's Day in Hong Kong
In support of International Women's Day (IWD) on March 8, the Paul, Weiss Hong Kong office participated in The Women's Foundation IWD gala lunch at the Conrad Hotel on March 4.
Paul, Weiss Sponsors The Women's Foundation Annual Gala Dinner in Hong Kong
Paul, Weiss is a sponsor of The Women's Foundation Annual Gala Dinner, which will include a keynote speech by Madeline Di Nonno, CEO of the Geena Davis Institute on Gender in Media.
Client Alert: SEC FCPA Action Against Bristol-Myers Squibb Highlights Importance of Addressing Red Flags
On October 5, 2015 the U.S. Securities and Exchange Commission announced it had settled an enforcement action against U.S. issuer Bristol-Myers Squibb Company, in which the SEC alleged violations of the internal controls and…
Paul, Weiss Sponsors 30% Club Boardroom Lunch for Aspiring Women Directors in Hong Kong
Paul, Weiss is a sponsor of the 30% Club's Annual Boardroom Lunch. The lunch will bring together an extensive and growing pool of accomplished and aspiring women directors with chairmen, board members and senior management from Hong…
Paul, Weiss Sponsors Women in Law Network in Hong Kong
Paul, Weiss is sponsoring and supporting the launch of Women in Law Hong Kong, a newly established networking platform for private practice lawyers and in-house counsel in Hong Kong.
Jack Lange Moderates Panel at IFLR South East Asia Forum
Hong Kong partner Jack Lange moderated a panel at the IFLR South East Asia Forum in Singapore on April 25. The panel, titled "Mitigating Risk in M&A and PE Transactions," discussed regional trends impacting deal…
Client Alert: China's Draft Foreign Investment Law to Revolutionize Foreign Investment Regime in China
On January 19, 2015, the PRC Ministry of Commerce released a draft Foreign Investment Law (the "Draft Law") for public comment. The Draft Law proposes to replace the current foreign investment regime with a new system and also…
Paul, Weiss Celebrates Three Decades in Hong Kong
Paul, Weiss celebrated its 30th anniversary in Hong Kong with a cocktail reception at the Hong Kong Club, in the building where its offices are located.
Of Counsel Jerome Cohen Awarded Honorary Doctorate of Law from Yale University
On May 18, corporate of counsel Jerome Cohen, a pioneering scholar of Chinese business and human rights law, was presented with his third degree from Yale University: an honorary Doctor of Law.
Betty Yap and Jack Lange Highlighted in Legal 500 Asia Pacific Hall of Fame
Corporate partners Betty Yap and Jack Lange were recognized in The Legal 500 Asia Pacific Hall of Fame for their excellent achievement in private equity work in Hong Kong.
Paul, Weiss Wins Four China Business Law Awards
Paul, Weiss was recognized by the China Business Law Journal as an international law firm winner in the categories of "Private Equity & Venture Capital," "IT, Telecom & E-Commerce," "Media, Entertainment & Sports" and…
Paul, Weiss Receives FinanceAsia 2018 Achievement Award
Paul, Weiss was recognized by FinanceAsia at its annual Achievement Awards for the "Best Equity Deal."
Paul, Weiss Deal for HP Wins ALB Korea Law Award
HP's acquisition of Samsung's printer business for $1.05 billion, in which Paul, Weiss represented HP, has been awarded the Technology, Media and Telecommunications Deal of the Year at the 6th Annual Asian Legal Business (ALB) Korea…
Paul, Weiss Wins Three China Business Law Awards
Paul, Weiss was recognized by China Business Law Journal as an international law firm winner in the categories of "Entertainment & Sports," "Private Equity & Venture Capital" and "Technology, Media and Telecommunications" at…
Jack Lange Receives Lifetime Achievement Award From Chambers
Hong Kong-based corporate partner Jack Lange received the 2018 Chambers Asia-Pacific Lifetime Achievement award in recognition of his contribution to the Asian legal arena.
Jack Lange Elected Chairman of American Chamber of Commerce in Hong Kong
Corporate partner Jack Lange has been elected as the Chairman of the American Chamber of Commerce in Hong Kong (AmCham) for 2018.
Paul, Weiss Shortlisted for Five ALB Hong Kong Law Awards
Paul, Weiss has been shortlisted by Asian Legal Business, a publication of Thomson Reuters, in five categories in its 2017 ALB Hong Kong Law Awards.
Media Law International Recognizes Paul, Weiss as a Tier 1 Firm in China and Hong Kong
For the third consecutive year, Paul, Weiss was recognized by Media Law International as one of four Tier 1 firms for media law in China and Hong Kong.
Paul, Weiss Awarded Deal of the Year by Asian-mena Counsel
Paul, Weiss was awarded a 2016 "Deal of the Year" by Asian-mena Counsel for our involvement as international counsel in MUFG's groundbreaking TLAC (total loss-absorbing capacity) bond offering
Paul, Weiss was awarded "Deal of the Year – Capital Markets" by the Asia Business Law Journal for our role in representing IDG Capital and its portfolio company Titan Gas Technology Investment in Shun Cheong's reverse takeover and new …
Paul, Weiss Wins China Business Law Award for TMT
Paul, Weiss was recognized by China Business Law Journal as an international law firm winner in the "Technology, Media and Telecommunications" category of its 2016 China Business Law Awards.
Paul, Weiss Shortlisted for Two IFLR Asia Law Awards in Private Equity
Paul, Weiss has been shortlisted in two categories as part of the 2017 IFLR Asia Law Awards.
Paul, Weiss Wins Three China Law & Practice Awards
Paul, Weiss was selected for honors in multiple categories at the China Law & Practice Awards, including "Real Estate & Construction Deal of the Year" and "TMT Firm of the Year - International."
For the second consecutive year, Paul, Weiss was recognized by Media Law International as one of four Tier 1 firms for media law in China and Hong Kong.
Paul, Weiss Wins China Business Law Award for Private Equity
Paul, Weiss was recognized by China Business Law Journal as an international law firm winner in the "Private Equity and Venture Capital" category of its 2015 China Business Law Awards.
Hong Kong and Tokyo Offices Recognized at Asia Women in Business Law Awards
The Hong Kong office won the country award for best international firm and the Tokyo office was shortlisted for the Japan country award at the Euromoney Legal Media Group Asia Women in Business Law Awards 2015.
Paul, Weiss Recognized by Asian-MENA Counsel for Telecommunications, Media & Technology
Paul, Weiss received honorable mention as a "Firm of the Year 2015" for Telecommunications, Media & Technology by Asian-MENA Counsel magazine in their ninth annual survey of "In-House Community Representing Corporate Asia &…
Hong Kong and Tokyo Offices Shortlisted for Asia Women in Business Awards
For the second consecutive year, our Hong Kong and Tokyo offices were shortlisted for their gender diversity efforts in their respective countries.
Paul, Weiss Wins Two China Law & Practice Awards
Paul, Weiss was selected for two honors at the 2015 China Law & Practice Awards, including "Private Equity Deal of the Year" for our involvement in the take private transaction of Yongye International, Inc. and "Most…
Paul, Weiss Shortlisted at the Asian Legal Business Hong Kong Law Awards
Paul, Weiss was shortlisted for "M&A Deal of the Year" for our involvement in Microsoft's acquisition of Nokia's Devices Service Business and our work on Tencent and JD.com's investment in Bitauto.
Paul, Weiss Shortlisted for Four China Law & Practice Awards
Paul, Weiss has been shortlisted as a finalist in four categories as part of the 2015 China Law & Practice Awards.
Paul, Weiss Ranked as Tier 1 Media Law Firm in China and Hong Kong
Paul, Weiss was recognized as a Tier 1 firm for media law in China and Hong Kong by Media Law International. Our firm is ranked as one of two leading firms for media law in China and three leading firms in Hong…
Paul, Weiss Selected for Two China Business Law Awards
China Business Law Journal (CBLJ) recognized Paul, Weiss in two practice categories -- Private Equity and Venture Capital and Technology, Media and Telecommunications -- as part of its 2014 China Business Law Awards. Nominations…

redpajama_set_name: RedPajamaCommonCrawl


text:
Die Bul ist ein Patrouillenboot der palauischen Division of Marine Law Enforcement. Das Schiff wurde von der japanischen Nippon Foundation und der Sasakawa Peace Foundation dem Staat Palau geschenkt. Es ist das erste Boot dieser Klasse, das im Rahmen eines Förderprogrammes übergeben wurde, und wurde im Juli 2012 ausgeliefert.

Die Schwesterschiffe sind Kedam (2018),  Euatel (2017) und Kabekl M'tal (2015). Die Schiffe sollen vor allem als Fischereischutzboote eingesetzt werden.

Siehe auch
 Remeliik (Boot)

Fußnoten

Militärisches Patrouillenboot
Motorschiff
Schifffahrt (Palau)

redpajama_set_name: RedPajamaWikipedia


Parkside is a new contemporary porcelain and ceramic tile showroom in Chelsea with over 500 designs on offer, and many exclusives, from some of the world's most dynamic manufacturers. Unrivalled bespoke services include waterjet cutting, porcelain worktop fabrication and digital printing on to tiles.
This design-led tile specification company serving architects, designers, contractors and developers has long been a trusted tile source to the UK contract market. PARKSIDE helps specify contemporary porcelain, ceramic and natural stone tiles for every type of project. With Design Studios in Clerkenwell, Chelsea and Leicester and a Design Studio coming soon to the Cotswolds, the team has over 200 years combined experience in helping to create original and innovative projects.
We've been working with PARKSIDE across their PR and Social Media activity since 2017 supporting the development of the new brand, introducing it to the A&D community and planning activities. Last year PARKSIDE created a significant pop-up shipping container showroom for CDW18. This year they are opening their new flagship Design Studio in Clerkenwell designed by Feix&Merlin Architects, launching a new collection of contemporary tiles by Tom Pigeon and will be part of CDW19 as a Showroom partner.


There are different types of crime, like burglary and fraud. Scams, tricks and cons are all things to be aware of as well. Council's community safety team offers a range of services. There are services that support people who have been the victim of crime or affected by it.
Below you will find a list of all services. If you only want to see the services relevant to you, choose one of the links under Services for or Services for people with.
You can use advanced search to find a suitable service by keyword, location and type of service.


Titan Petrochemicals has entered into a sale and purchase agreement with Sino Team Investment Development for the acquisition of Gold Dragon Enterprise Development for HK$21m ($2.7m) in a cash plus shares deal.
Following the completion of the acquisition, Gold Dragon, which indirectly controls full equity of Jiangsu Hongqiang Heavy Industry, will become a subsidiary of Titan Petrochemicals.
Nantong-based Jiangsu Hongqiang Heavy Industry is a shipyard mainly engaged in the business of shipbuilding and manufacturing of steel structures.
Titan Petrochemicals believes the acquisition will enable the company to resume its shipbuilding business immediately and help the company build up its capability and track record, while the deal will also bring in an experienced shipbuilding management and operation team.
Following the completion of a long restructuring process, Titan has been expanding its ship repair business in the past months. The company acquired Zhoushan Yatai Shipbuilding Engineering in January and also entered into a MOU with Singapore's EMS Energy in March to fund the construction a shipyard in Singapore.
At the end of September, the High Court of Hong Kong moved to wind up Titan's controlling shareholder Guangdong Zhenrong Energy and Titan is now in the process of seeking legal advice and assessing the impact this may have on the company.


When I was writing our last post, I came across this audio-video montage of Ram Dass talking about Attachment and Addiction. Charles' approach to recovery is so similar and aligned with Ram Dass' comments on this subject – and Ram Dass is such an elegant speaker – that I thought you'd enjoy watching it.
There's one point Ram Dass made in this recording, that I'd like to focus on. He says you don't really get immediate gratification from a spiritual approach to recovery – you get something bigger than the rush you get from drugs, but you have to wait for it.
There are tools that will give you an immediate gulp of pure Life Energy that goes straight to your head, with no detours. Let's face it: Kai Chi Do gives you a spiritual high. That's why we say it's a metaphysical workout for body, mind, and spirit. The high comes from recovering your connection – what Ram Dass calls healing the separation.
But the challenge is learning how to keep the high – how to live your connection. Not just while your doing Kai Chi Do…or yoga, or meditation, or doing breathwork, or whatever works for you… but all the other hours of the day. In your relationships, in your job, in your thoughts. That's the part you have to cultivate and savor over time.
That's really our work. That's what Charles teaches.
It goes beyond recovery. It's just about having a full, vivid, and deliciously satisfying life.
To really benefit from a teacher or coach, you need to be able to give them your trust. Not everyone deserves that gift. But sometimes it's hard to tell the difference between form and substance. And when you are in pain or personal crisis, you could be willing to try anything.
They help you to become more powerful, rather than fostering dependency. There's a subtle trap that healers can fall into: They need you to be sick in order for them to have someone to heal. This is why we don't believe in people being "patients". We don't believe in the sick role because we know that everyone is powerful.
They know that you are the expert in what you need. You don't need any more people in your life telling you what to do. This is the trap of the expert role. It's an "I know something you don't know" or even "I'm the boss of you" attitude. That's arrogant; It's condescending. And it's controlling. But don't think it's always obvious. Well-meaning people can fall into this trap when you ask them to make decisions for you. Don't do that.
They know they're a piece of God, but they also know that they're not the whole enchilada. Steer clear of anyone who wants you to worship them. Remember the first commandment – Thou shalt have no other God before me – and choose a teacher who wants to create leaders, not devotees.
They can make a mistake. Beware of people who are too holy. We already mentioned the teachers who encourage you to worship them – the ones who create a holy hierarchy with them at the top. But there's another type of phony holy – the hypocrites. The ones who don't practice what they preach.
On this subject, you might want to read a book called Meeting the Shadow. It explores, for example, the achievements and the death of Chogyam Trungpa. Trungpa Rinpoche started over 100 Meditation Centers including the Shambhala Meditation Centers and Retreats and he founded Naropa Institute, the first accredited Buddhist University in North America. He also died, at the age of 48, from complications of alcoholism (as well as cocaine and Seconal).
The problem is not that he was fallible – The problem was that his secrets and hypocrisy were an abuse of power and a betrayal of trust.
You feel safe with them. Avoid a teacher who evokes fear. This often shows up in the message that there's only one Way and you'll suffer if you don't follow (their interpretation) of it. But leading by fear can also come in the form of criticism, disapproval, and group pressure to conform. It is thinly disguised in the teaching to "accept 100% responsibility" that really delivers blame. Listen to your inner guidance system and don't allow anyone to lead you with fear (or anger or intimidation).
They encourage your growth. The first time Charles went to India to see Sathya Sai Baba, the people who led the group were upset that Charles and Sai Baba formed a bond. They said to Charles, "If Sai Baba is your spiritual teacher now, who are we to you?" We didn't hang out with them too long after that.
You want a coach or teacher who loves it when you find a whole truckload of supports, resources, and tools. They get a thrill from your path of exploration and discovery. They're not competing with anybody else and they're not competing with you. They're not jealous. They celebrate when you're happy. They don't own you, and – as much as they love you and care about you – they don't need you.
They help you problem solve. We've seen therapists and gurus who are completely non-directive. It's the opposite of the expert role, but it's still a kind of condescension, like they're above it all and they're just waiting for it to dawn on you that the solution to every problem is to transcend it. Stuff matters! If you're hurting, it matters to you. Find a teacher who shows compassion and will actually give you constructive suggestions. They don't drown in your pain but they don't just sit in the I.T. (the Ivory Tower) either.
Most of the cautions about teachers boil down to someone having a "Big Me – little you" attitude or trying to possess you. Don't buy it. Give your trust to people who respect you and can help you to find the best in yourself.
Interested in coaching with Charles? Click here.


text:
Silvano Mosqueira (* Carapeguá, República del Paraguay; 11 de septiembre de 1875 –† Buenos Aires, Argentina; 15 de agosto de 1954), artista paraguayo.

Hijo de Dionisia Mosqueira. Realizó sus estudios primarios en Paraguarí, Asunción y Buenos Aires.

Primeros pasos

De regreso al país se incorporó a la administración pública y al servicio exterior de la Cancillería paraguaya y realizó una importante labor de divulgación cultural. Fue Secretario de la Intendencia Municipal de Asunción, Jefe de Sección en el Archivo Nacional, agregado a la legación ante los gobiernos de los Estados Unidos y México, Cónsul General en Río de Janeiro, Director de la Sección Política y Diplomática del Ministerio de Relaciones Exteriores, Encargado de Negocios en Río de Janeiro, Director de la Sección Biblioteca, Archivo y Expedición del Ministerio de Relaciones Exteriores y Cónsul en Rosario, Argentina.

Trayectoria

A la par de sus numerosos cargos públicos, se dedicó a las letras, escribiendo poesía en guaraní y ensayos biográficos de figuras del mundo político e intelectual de su época. Al mismo tiempo, fue formando una rica biblioteca. Su vasta información, su contacto directo con las fuentes, su afán por conocer y divulgar episodios de la historia de su patria, además de aquellos de los que fue testigo y actor, hicieron de él una obligada fuente de información.

El incansable intelectual argentino, radicado en el Paraguay desde hace más de cuarenta años, Raúl Amaral, dice acerca de Mosqueira: "...su obra, si no copiosa, por lo menos, de significativo valor, permanece a la sordina y su nombre no figura -elocuente injusticia- entre aquellos novecentistas que activaron la marcha de la cultura nacional..." Y Viriato Díaz-Pérez, el ilustre hombre de letras español avecindado al Paraguay, expresa: "(Mosqueira es un) ... Laborioso difundidor de cultura literaria e histórica; biógrafo meritísimo, autor de ensayos y semblanzas sobre personalidades patricias y hechos memorables, cronista de bellas y generosas evocaciones y uno de los grandes propulsores y animadores en el mundo intelectual paraguayo. Escritor idealista y patriota".

Últimos años
Falleció en Buenos Aires, soltero y sin descendencia, el 15 de agosto de 1954.

Obras
Entre sus principales obras figuran "El general José E. Díaz", "Páginas sueltas", "Semblanzas paraguayas", "Ideales", "Impresiones de los Estados Unidos", "Siluetas femeninas", "Juan Silvano Godoi: su vida y su obra"; "Nuevas semblanzas", "El Paraguay", "Intercambio intelectual americano" y el prólogo a la segunda edición del ensayo de Blas Garay "El comunismo en las Misiones".

Referencias
 Centro Cultural de la República El Cabildo
 Diccionario Biográfico "FORJADORES DEL PARAGUAY", Primera Edición enero de 2000. Distribuidora Quevedo de Ediciones. Buenos Aires, Argentina.

Emigrantes paraguayos hacia Argentina
Escritores en español
Escritores en guaraní
Escritores masculinos de Paraguay
Paraguarienses


text:
/**4. create Object for view dynamic template */
import { Component, Input, ngOnInit , ViewChild, ComponentFactoryResolver, OnDestroy } from '@angular/core';

import { AnswerDirective } from './answer.directive.ts';
import { AnswerItem }      from './answer-item.ts';
import { AnswerComponent } from './answer.component.ts';
import { Answer } from '../../model/answer.ts';

import {ExamAnswerComponent} from '../../components/answer/exam.answer.component.ts';
import {PollAnswerComponent} from '../../components/answer/poll.answer.component.ts';
@Component({
  selector: 'show-answer-component',
  entryComponents: [ ExamAnswerComponent, PollAnswerComponent ],
  template: `
<ng-template answer-host ></ng-template>
            `
})
export class ShowAnswerComponent implements ngOnInit , OnDestroy {
  //@Input() ads: AnswerItem[];
  @Input() ads: AnswerItem[] = [];
  currentAddIndex: number = -1;
  @ViewChild(AnswerDirective) adHost: AnswerDirective;
  subscription: any;
  interval: any;
  showRadio:boolean=false;
  answer:Answer = new Answer();
  constructor(private componentFactoryResolver: ComponentFactoryResolver) { }

  ngOnInit () {
    this.loadComponent();
    //this.getAds();
  }

  ngOnDestroy() {
    clearInterval(this.interval);
  }

  loadComponent() {
    let adItem = this.ads;
    let componentFactory = this.componentFactoryResolver.resolveComponentFactory(adItem.component);

    let viewContainerRef = this.adHost.viewContainerRef;
    viewContainerRef.clear();

    let componentRef = viewContainerRef.createComponent(componentFactory);
    (<AnswerComponent>componentRef.instance).data = adItem.data;

  }

  onSelectDelete(answer:Answer):void{
      console.log("remove at : "  );

  }
}


The Filmlosophers, Eddie Villanueva and Chad Riley, review Disney's Moana (2016), a non-Pixar animated tale with a colorful cast of characters and a distinctly mythological bent. Featuring song lyrics from Broadway star Lin-Manuel Miranda and starring newcomer Auli'i Cravalho as Moana alongside Dwayne "The Rock" Johnson as demigod Maui, the film offers a refreshingly modern take on the well-honed Disney model of filmmaking.
Other news items include reports of a Highlander remake from John Wick and John Wick 2 director Chad Stahelski, and an exciting casting announcement for Marvel's Black Panther film as it adds Angela Bassett in a key role.


text:
Tag Archives: Tibet
"How do you sleep at night?" I asked character comedian Matt Roper two days ago in Buenos Aires
Matt Roper as himself at the Edinburgh Fringe in 2012
On 10th January, I got an e-mail from British comedian Matt Roper. It said:
"Albuquerque, New Mexico? Or Tuscon, Arizona? I'm at truck stop in New Mexico and I can get to either place to get to where I need to be. But I can only choose one. Your thoughts?"
"The Wikipedia entry on Albuquerque," I told him, "has sections on Freight Service and Sanitation. If the only thing they can write about Albuquerque to make it sound interesting is its sanitary arrangements, the town has not a lot going for it.
"As for Tucson, Wikipedia says: The Arizona Daily Wildcat is the University of Arizona's student newspaper and the Aztec News is the Pima Community College student newspaper. The New Vision is the newspaper for the Roman Catholic Diocese of Tucson and the Arizona Jewish Post is the newspaper of the Jewish Federation of Southern Arizona. You can't go wrong. It has everything."
Matt decided to go to Tucson and, on the Greyhound bus trip, he got talking to a bounty hunter. But that's another story.
When I talked to him two days ago, Matt was in Buenos Aires, Argentina.
"I flew into New York and managed to do everything by train up until Texas and then I ended up doing car shares and Greyhound buses," he told me. "I really like them, because you really meet the real characters on the buses."
"Who's the most bizarre person you met?" I asked him.
"Maybe the bounty hunter. Maybe the pimp's nephew. There was the 18-stone Baptist preacher who tried to convert me to Southern Baptism. And the guy who coached Bobby Fischer, the chess champion. I think that guy is living in abject poverty in New York; he's in his seventies, drinking quite heavily. He never received any money. Bobby Fischer went on to make loads and loads and he never gave the guy any."
"But now you're in Buenos Aires," I said. "I'm green with envy. You're just basically meandering around the world."
"I'm always writing and trying stuff out, doing gigs here and there," said Matt.
He performs as the rather greasy, slightly lecherous but strangely charming Spanish lounge lizard singer Wilfredo.
An audio EP of Wilfredo's songs was recently released
An EP of his songs The Wonderful World of Wilfredo has just been released on iTunes and a documentary film Wilfredo Comes To Town is doing the festival rounds.
"I got connected with some local comics and ended up doing a gig here last night," Matt told me on Skype. "It was interesting doing a Spanish character in Buenos Aires. I felt as if I was being fed to the lions. But it went well. It's been really inspirational.
Matt Roper (left) with Argentinian comic Gregorio Rossello in Buenos Aires this week
"The Argentinian comedy scene isn't huge, but I met some local comedians. There's a group of four young Argentinian comics who flyer every weekend. Their work ethic is so inspirational. They hire this little room above a pub like we do in London – 60 capacity. They flyer all day and night on a Friday and Saturday and do three shows a night every weekend – a 10.00pm, 01.00am and 03.00am show – because no-one goes to bed here till gone dawn.
"I have a blessed life. I support myself with writing commissions and gigs."
"Yes," I said, "You write these promo scripts, which is sort-of like what I used to do. But I had to go to places like Salford. You get to travel the world and work via the internet."
"You've been to Tibet," said Matt. "I haven't been to Tibet. I've never seen the Potala Palace."
"You've come to my home," I said. "You've seen the picture."
"I've seen the Dalai Lama," Matt said.
"I've only seen him talk at Wembley," I said. "You've been more exotic."
"I was an English teacher in China for six months when I was about 27," said Matt, "teaching adults. I used to wind them up. I would play Odd One Out with them. I'd put the names of four towns on the board and get them to pick which one didn't belong, say: Lhasa, Beijing, Shanghai, Shenzhen. Beijing! they'd say – Why? – Capital city! – Good, but wrong. It's Lhasa, cos Lhasa's the only one that's not in China! They'd go ballistic. I'd been with the Tibetan community in exile at Dharamsala in northern India."
"Have you seen the Iguassu waterfalls yet?" I asked.
"No," said Matt. "I fly out of Buenos Aires in five hours. Basically, I've come all the way to Argentina, rented an apartment out in the suburbs of Buenos Aires, miles away from anywhere, and mostly what I've done is sit here and written, drunk a few bottles of wine and taken a taxi into town every now and then. It's ridiculous."
"So you haven't seen the pampas," I said. "You haven't seen men on horseback with large balls. None of that?"
"Say hello to my leetle friendz" Matt with his cockroach killers
"None of that," agreed Matt. "But I've seen cockroaches. I don't mind insects and I love animals, but cockroaches! Buenos Aires is one of the great cockroach cities of the world. You can see them all weaving in-and-out of the human traffic on the pavements. But there's nothing you can do about it. It's not because the place is dirty. It's the heat and… I just can't fucking cope with cockroaches. I don't want to cook. I lose my appetite."
"How do you sleep at night?" I asked.
"I just leave the light on. They don't like lights and they don't like noise. So I usually keep some music on."
"So why," I asked, "did you want to go to Buenos Aires?"
"Because I had to leave the States cos my visa was up and I've always wanted to come to Buenos Aires. But I'm going back to the States now… LA and New York… I have to leave the apartment in 35 minutes. Cockroaches can survive nuclear holocausts, you know."
"And you're back in Britain in May?"
"Yes. And then I'm doing a tour of Central Europe in June with your Facebook friend Alex Frackleton, because he's keen to get back into stand-up. We play Budapest, Bratislava, Vienna, Prague, two dates at an arts festival in the Czech Republic and I'm hoping to play Martin Soan's Pull The Other One club in Leipzig as well."
"I saw the first show there," I said. "It was full. They had to turn people away. Alex Frackleton told me there was a story about you and him meeting up in Prague."
Matt Roper and Alex Frackleton with their unknown Czech friend
"Yes, we went to the big Gay Pride event in Prague," said Matt, "and were photographed with an enormous transvestite. Alex was looking up: Can we have a photograph? – We're not gay! We're comedians! – We're not gay! We're comedians!"
"Why might you play Leipzig?" I asked.
"Because it's Martin Soan and because it's close to Prague and because my dental technician is in Berlin. She's the woman who makes Wilfredo's teeth."
Yes, dear reader, Matt Roper wears specially-constructed teeth when he performs as Wilfredo.
"Have you got two sets for safety?" I asked Matt.
"Yes, I always keep one set in my pocket, just in case the first set fly out and break. You gotta have spare teeth, John!"
"No embarrassing questions at Customs yet?" I asked.
"Not yet," said Matt. "But, when I got to Buenos Aires, I unzipped my bag and the owners of the apartment saw this pair of big teeth and a black wig. Because I don't speak much Spanish and they didn't speak English, there was nothing said. Just this silence."
"I always think travelling makes people better people," I said. "But has it made you a better comedian?"
"I think the States has given me tons of material," said Matt. "Not so much Argentina. I think Argentina is more similar to Britain than the States is. It seems to me that Argentinians enjoy nothing more than to see somebody fail. Like the British. They're very pessimistic. Whereas, in the States, they love to see people succeed. They nurture success and I find that quite attractive. All this Have a nice day! stuff wound me up at first. Have the best day of your life, sir! But, after a while, with everybody saying it, it's actually quite nice. It's better than calling somebody a cunt."
"In Glasgow, calling someone a cunt is a term of affection," I said, "according to Janey Godley and Jerry Sadowitz."
"I don't know Janey that well," laughed Matt, "but we were both on the Nicholas Parsons show together in Edinburgh and, when she looked across at Wilfredo, she said: Fucking hell! 25 years ago I would have fucking married you!
"Me, half my family is Irish Catholic. My dad's family is Liverpool, which is naturally like a Celtic city. All the religious suppression, all the guilt is good for comedy. I think that's why Liverpool is such a great comedy city. And Glasgow. From that religious suppression comes a lot of humour. How else are they going to get through the day?"
An extract from the documentary Wilfredo Comes To Town in which Matt's character sings Moon River is on YouTube.
Filed under Argentina, Comedy, Eccentrics, Humor, Humour, US
Tagged as Agentina, Albuquerque, Bobby Fischer, Buenos Aires, China, cockroaches, comedy, Dalai Lama, eccentrics, Glasgow, Greyhound bus, janey godley, Jerry Sadowitz, Liverpool, Martin Soan, Matt Roper, Tibet, Tucson, USA, Wilfredo
Sep 23, 2011 · 10:08 am
The greatest mystery in all of China is to be found in a Northwood restaurant
I will be going to see more movies in the China Image Film Festival in London later today.
In round figures, there are 4,000 cinema screens in the UK.
In China – a vastly larger country – there are only 6,000 screens.
But, within the next five years, China will have 20,000 screens and will become the second biggest film industry in the world after the US – larger than India's Bollywood. In the last year alone, there were 500 films made in China.
I had a meal in a Chinese restaurant in Northwood last night, not far from 'the bunker', and got home to watch yet more on the BBC News channel about a world economic situation that is barely – or perhaps not – under control. All the 'advanced' countries seem to be in debt that will stretch decades into the future.
But China is sitting on vast amounts of money. The irony of a Communist country becoming rich on capitalism.
The last decade was all about China making things but the next decade will be all about China owning things.
Which reminds me of something a history teacher once said as a throwaway line at my school when I was about 13.
He said: "Civilisation and power moves westwards because invading armies have always ridden westwards, following the daylight."
Trite, of course.
But, in the northern hemisphere, it is roughly true.
At the moment, power is moving from North America to the Pacific Rim (a phrase that always sounds to me like a dubious sexual practice).
What confuses me is that the Chinese are very expansionist of late.
They have been putting money into Africa, especially into very suspect regimes, for a couple of decades. They are building an aircraft carrier or, at least, have refitted a Russian one. They are now investing heavily in the West.
This seems very un-Chinese. The Great Wall was built to keep the uncivilised long-nosed foreign devils out and to preserve the integrity of China which, with quite a lot of justification, looked inward at itself as the only truly civilised place.
Japan was always the regional expansionist power, not China.
Of course, there was the invasion of Tibet in 1949, but that seemed an unfortunate exception to the rule and a knee-jerk reaction after Mao Tse-tung's Communists took power.
It seems to be very un-Chinese to be expansionist. It is a great mystery.
Though, sitting in a Chinese restaurant in Northwood last night, it was secondary as a mystery in my mind to the greater ongoing mystery of why the Chinese – who, let's face it, invented pretty much everything – never invented the teacup handle not the knife-and-fork. And why on earth were chopsticks thought to be a good idea in a nation where the staple diet was and is based around small grains of rice?
Life is a constant mystery.
Filed under China, Food, History, Movies, Travel
Tagged as aircraft carrier, Bollywood, bunker, capitalism, China, chopsticks, cinema, civilisation, civilization, communism, economy, empire, expansionism, film, foreign devil, Great Wall, Hollywood, Image Film Festival, industry, Mao Tse-tung, movie, NATO, North America, Northwood, Pacific Rim, recession, restaurant, rice, rimming, Tibet
Apr 21, 2011 · 12:44 pm
The mystery of a £500 million man, the German love of Red Indians and the tough future for seven dwarfs.
I was in Brighton yesterday, visiting a friend. Her partner comes from Wolverhampton.
When I arrived, she asked me: "Have you heard about Snow White?"
"Erm, no" I said, "No, I don't think so."
"Apparently," she told me, "Radio 4 says the local panto in Wolverhampton this year is Snow White, but they have sacked the seven dwarfs… Sacked them! Suddenly!"
I looked at my friend.
"What on earth did they do?" I asked.
I had visions of the legendary mayhem and Bacchanalia which reportedly happened among the Munchkins during the filming of The Wizard of Oz.
"They didn't do anything wrong," my friend explained. "It was the economic recession and the soaring cost of dwarfs… The theatre is going to replace the dwarfs with children wearing masks."
"It won't be the same," I replied. "Don't Look Now would't have been the same. Didn't they think about the soaring cost of vertically-challenged people before they employed the seven dwarfs in the first place?"
"Radio 4 didn't say."
"That seems a bit remiss of them. Standards are falling at the BBC."
"Yes," my friend replied.
"We live in a strange and mysterious world," I said.
We had a cup of tea.
Later in the afternoon, in The Lanes, we picked up a leaflet for the Brighton Festival Fringe. At the top, it said: The third largest Fringe in the world.
"Brighton has always been billed as the second biggest," my friend said.
"You've been shamed," I ventured. "Edinburgh is by far the biggest arts festival in the world and the biggest Fringe. What on earth is the second biggest?"
"It's a mystery to me," said my friend.
So we went to Brighton's always surreal-sounding Vegetarian Shoes shop and stared in the window. Nearby, was a man sitting on the ground outside a Native American shop; he was dressed as a Tibetan lama and was apparently talking on his mobile phone to his girlfriend; he had an English accent.
"They're very popular in Germany," my friend told me.
"Tibetan monks?" I asked.
"Native American artifacts."
"I seem to remember reading," I said, "that German movie-goers are very fond of Westerns, too. What's that all about?"
"I can't help feeling that, if Hitler had dressed in a Red Indian head-dress, it would have undermined his credibility," I suggested.
My friend looked at me.
She said nothing.
Any news of Nicholas van Hoogstraten?" I asked, as we walked on. I'm always interested in people with unusual lives and my friend had once given me a biography of van Hoogstraten as a Christmas present.
By 1968 (aged 23), he simultaneously became Britain's youngest millionaire and started a 4-year prison sentence for paying a gang to throw a grenade into the house of Rev Braunstein, a Jewish leader whose eldest son owed him £3,000. He later said of the people who threw the grenade: "These weren't anarchists: they were businessmen, respectable people."
In 2002, he was sentenced to ten years' imprisonment for the manslaughter by two other men of business rival Mohammed Raja; a jury decided that "although he wanted Mr Raja harmed, he had not wanted him murdered". He was released in 2004 after successfully appealing against his conviction on the grounds that "there was no foundation for a manslaughter case." In 2005, Mohammed Raja's family won £6 million in a civil action against van Hoogstraten after the court found that the balance of probabilities was "that the recruitment of the two thugs was for the purpose of murdering Mr Raja and not merely frightening or hurting him". Van Hoogstraten reportedly told the BBC that the family would "never get a penny".
"Is he still in Brighton?" I asked my friend.
"It's a mystery to me," my friend said. "Every now and then you hear stories. Some people say he's in Zimbabwe."
"Among friends, then," I said.
"Not any more," my friend said. "One story is he sold all his assets in this country and put all his money into Zimbabwe because he was so chummy with the regime but they fell out and he lost all his land there."
The last time I heard van Hoogstraten, he was on BBC Radio 4's Today programme defending Robert Mugabe's 'land reform' policies.
"How's van Hoogstraten mausoleum?" I asked.
"Crumbling," my friend said.
By this point, we were passing a bronze statue of the British music hall star Max Miller.
"An interesting place, Brighton," I said. "Max Miller and Nicholas van Hoogstraten were both equally at home here."
"Yes," said my friend.
"Bronze is very colourless for Max Miller," I said.
Apparently Adelaide is the second biggest Fringe in the world.
And, according to Wikipedia, which is surprisingly accurate on such things, Nicholas van Hoogstraten has been reported to be worth £500 million, "though he has stated that his assets in the UK have all been placed in the names of his children". His assets in property and farming in Zimbabwe were estimated to be worth over £200 million.
I don't know what he is worth now or where he is. Nor does my friend.
All I know for certain is that life is tough for dwarfs in Wolverhampton.
Filed under Comedy, Crime, History, Theatre, Travel
Tagged as Adelaide Fringe, artifacts, arts festival, bacchanalia, bbc, biggest, biography, Braunstein, Brighton, Brighton Fringe, Britain, british, Don't Look Now, economic, edinburgh fringe, England, Equity, festival, Germany, grenade, Hitler, lama, land reform, mausoleum, Max Miller, mayhem, Mohammed Raja, Monk, movie, Munchkins, music hall, native American, Nicholas van Hoogstraten, orgies, panto pantomime, radio 4, recession, Red Indians, Robert Mugabe, seven dwarfs, Snow White, The Lanes, The Wizard of Oz, Tibet, Tibetan, Today, uk, United Kingdon, variety, vaudeville, vegetarian shoes, vertically challenged, western, Wolverhampton, Zimbabwe


You will find Dedham Civic Pride's "Sponsor-A-Spot" in all neighborhoods of Dedham. These colorfully landscaped traffic islands and pocket gardens are supported by the financial assistance of local businesses. The spots are planted, weeded and watered by the staff of Dedham Civic Pride.
If you would like to help Dedham Civic Pride continue to improve and upgrade areas in Dedham, please consider Sponsoring a Spot. Spots run from $275 to $500 depending on the plant needs and size.
For more information, please contact Janet Holmes at 781-249-9258.