text:
title: "Custom State Serialization"
weight: 8
type: docs
aliases:
  - /dev/stream/state/custom_serialization.html
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

# Custom Serialization for Managed State

This page is targeted as a guideline for users who require the use of custom serialization for their state, covering
how to provide a custom state serializer as well as guidelines and best practices for implementing serializers that allow
state schema evolution.

If you're simply using Flink's own serializers, this page is irrelevant and can be ignored.

## Using custom state serializers

When registering a managed operator or keyed state, a `StateDescriptor` is required
to specify the state's name, as well as information about the type of the state. The type information is used by Flink's
[type serialization framework]({{< ref "docs/dev/serialization/types_serialization" >}}) to create appropriate serializers for the state.

It is also possible to completely bypass this and let Flink use your own custom serializer to serialize managed states,
simply by directly instantiating the `StateDescriptor` with your own `TypeSerializer` implementation:

{{< tabs "ee215ff6-2e21-4a40-a1b4-7f114560546f" >}}
{{< tab "Java" >}}
```java
public class CustomTypeSerializer extends TypeSerializer<Tuple2<String, Integer>> {...};

ListStateDescriptor<Tuple2<String, Integer>> descriptor =
    new ListStateDescriptor<>(
        "state-name",
        new CustomTypeSerializer());

checkpointedState = getRuntimeContext().getListState(descriptor);
```
{{< /tab >}}
{{< tab "Scala" >}}
```scala
class CustomTypeSerializer extends TypeSerializer[(String, Integer)] {...}

val descriptor = new ListStateDescriptor[(String, Integer)](
    "state-name",
    new CustomTypeSerializer)
)

checkpointedState = getRuntimeContext.getListState(descriptor)
```
{{< /tab >}}
{{< /tabs >}}

## State serializers and schema evolution

This section explains the user-facing abstractions related to state serialization and schema evolution, and necessary
internal details about how Flink interacts with these abstractions.

When restoring from savepoints, Flink allows changing the serializers used to read and write previously registered state,
so that users are not locked in to any specific serialization schema. When state is restored, a new serializer will be
registered for the state (i.e., the serializer that comes with the `StateDescriptor` used to access the state in the
restored job). This new serializer may have a different schema than that of the previous serializer. Therefore, when
implementing state serializers, besides the basic logic of reading / writing data, another important thing to keep in
mind is how the serialization schema can be changed in the future.

When speaking of *schema*, in this context the term is interchangeable between referring to the *data model* of a state
type and the *serialized binary format* of a state type. The schema, generally speaking, can change for a few cases:

 1. Data schema of the state type has evolved, i.e. adding or removing a field from a POJO that is used as state.
 2. Generally speaking, after a change to the data schema, the serialization format of the serializer will need to be upgraded.
 3. Configuration of the serializer has changed.

In order for the new execution to have information about the *written schema* of state and detect whether or not the
schema has changed, upon taking a savepoint of an operator's state, a *snapshot* of the state serializer needs to be
written along with the state bytes. This is abstracted a `TypeSerializerSnapshot`, explained in the next subsection.

### The `TypeSerializerSnapshot` abstraction

```java
public interface TypeSerializerSnapshot<T> {
    int getCurrentVersion();
    void writeSnapshot(DataOuputView out) throws IOException;
    void readSnapshot(int readVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException;
    TypeSerializerSchemaCompatibility<T> resolveSchemaCompatibility(TypeSerializer<T> newSerializer);
    TypeSerializer<T> restoreSerializer();
}
```
```java
public abstract class TypeSerializer<T> {

    // ...

    public abstract TypeSerializerSnapshot<T> snapshotConfiguration();
}
```

A serializer's `TypeSerializerSnapshot` is a point-in-time information that serves as the single source of truth about
the state serializer's write schema, as well as any additional information mandatory to restore a serializer that
would be identical to the given point-in-time. The logic about what should be written and read at restore time
as the serializer snapshot is defined in the `writeSnapshot` and `readSnapshot` methods.

Note that the snapshot's own write schema may also need to change over time (e.g. when you wish to add more information
about the serializer to the snapshot). To facilitate this, snapshots are versioned, with the current version
number defined in the `getCurrentVersion` method. On restore, when the serializer snapshot is read from savepoints,
the version of the schema in which the snapshot was written in will be provided to the `readSnapshot` method so that
the read implementation can handle different versions.

At restore time, the logic that detects whether or not the new serializer's schema has changed should be implemented in
the `resolveSchemaCompatibility` method. When previous registered state is registered again with new serializers in the
restored execution of an operator, the new serializer is provided to the previous serializer's snapshot via this method.
This method returns a `TypeSerializerSchemaCompatibility` representing the result of the compatibility resolution,
which can be one of the following:

 1. **`TypeSerializerSchemaCompatibility.compatibleAsIs()`**: this result signals that the new serializer is compatible,
 meaning that the new serializer has identical schema with the previous serializer. It is possible that the new
 serializer has been reconfigured in the `resolveSchemaCompatibility` method so that it is compatible.
 2. **`TypeSerializerSchemaCompatibility.compatibleAfterMigration()`**: this result signals that the new serializer has a
 different serialization schema, and it is possible to migrate from the old schema by using the previous serializer
 (which recognizes the old schema) to read bytes into state objects, and then rewriting the object back to bytes with
 the new serializer (which recognizes the new schema).
 3. **`TypeSerializerSchemaCompatibility.incompatible()`**: this result signals that the new serializer has a
 different serialization schema, but it is not possible to migrate from the old schema.

The last bit of detail is how the previous serializer is obtained in the case that migration is required.
Another important role of a serializer's `TypeSerializerSnapshot` is that it serves as a factory to restore
the previous serializer. More specifically, the `TypeSerializerSnapshot` should implement the `restoreSerializer` method
to instantiate a serializer instance that recognizes the previous serializer's schema and configuration, and can therefore
safely read data written by the previous serializer.

### How Flink interacts with the `TypeSerializer` and `TypeSerializerSnapshot` abstractions

To wrap up, this section concludes how Flink, or more specifically the state backends, interact with the
abstractions. The interaction is slightly different depending on the state backend, but this is orthogonal
to the implementation of state serializers and their serializer snapshots.

#### Off-heap state backends (e.g. `EmbeddedRocksDBStateBackend`)

 1. **Register new state with a state serializer that has schema _A_**
  - the registered `TypeSerializer` for the state is used to read / write state on every state access.
  - State is written in schema *A*.
 2. **Take a savepoint**
  - The serializer snapshot is extracted via the `TypeSerializer#snapshotConfiguration` method.
  - The serializer snapshot is written to the savepoint, as well as the already-serialized state bytes (with schema *A*).
 3. **Restored execution re-accesses restored state bytes with new state serializer that has schema _B_**
  - The previous state serializer's snapshot is restored.
  - State bytes are not deserialized on restore, only loaded back to the state backends (therefore, still in schema *A*).
  - Upon receiving the new serializer, it is provided to the restored previous serializer's snapshot via the
  `TypeSerializer#resolveSchemaCompatibility` to check for schema compatibility.
 4. **Migrate state bytes in backend from schema _A_ to schema _B_**
  - If the compatibility resolution reflects that the schema has changed and migration is possible, schema migration is
  performed. The previous state serializer which recognizes schema _A_ will be obtained from the serializer snapshot, via
   `TypeSerializerSnapshot#restoreSerializer()`, and is used to deserialize state bytes to objects, which in turn
   are re-written again with the new serializer, which recognizes schema _B_ to complete the migration. All entries
   of the accessed state is migrated all-together before processing continues.
  - If the resolution signals incompatibility, then the state access fails with an exception.

#### Heap state backends (e.g. `HashMapStateBackend`)

 1. **Register new state with a state serializer that has schema _A_**
  - the registered `TypeSerializer` is maintained by the state backend.
 2. **Take a savepoint, serializing all state with schema _A_**
  - The serializer snapshot is extracted via the `TypeSerializer#snapshotConfiguration` method.
  - The serializer snapshot is written to the savepoint.
  - State objects are now serialized to the savepoint, written in schema _A_.
 3. **On restore, deserialize state into objects in heap**
  - The previous state serializer's snapshot is restored.
  - The previous serializer, which recognizes schema _A_, is obtained from the serializer snapshot, via
  `TypeSerializerSnapshot#restoreSerializer()`, and is used to deserialize state bytes to objects.
  - From now on, all of the state is already deserialized.
 4. **Restored execution re-accesses previous state with new state serializer that has schema _B_**
  - Upon receiving the new serializer, it is provided to the restored previous serializer's snapshot via the
  `TypeSerializer#resolveSchemaCompatibility` to check for schema compatibility.
  - If the compatibility check signals that migration is required, nothing happens in this case since for
   heap backends, all state is already deserialized into objects.
  - If the resolution signals incompatibility, then the state access fails with an exception.
 5. **Take another savepoint, serializing all state with schema _B_**
  - Same as step 2., but now state bytes are all in schema _B_.

## Predefined convenient `TypeSerializerSnapshot` classes

Flink provides two abstract base `TypeSerializerSnapshot` classes that can be used for typical scenarios:
`SimpleTypeSerializerSnapshot` and `CompositeTypeSerializerSnapshot`.

Serializers that provide these predefined snapshots as their serializer snapshot must always have their own, independent
subclass implementation. This corresponds to the best practice of not sharing snapshot classes
across different serializers, which is more thoroughly explained in the next section.

### Implementing a `SimpleTypeSerializerSnapshot`

The `SimpleTypeSerializerSnapshot` is intended for serializers that do not have any state or configuration,
essentially meaning that the serialization schema of the serializer is solely defined by the serializer's class.

There will only be 2 possible results of the compatibility resolution when using the `SimpleTypeSerializerSnapshot`
as your serializer's snapshot class:

 - `TypeSerializerSchemaCompatibility.compatibleAsIs()`, if the new serializer class remains identical, or
 - `TypeSerializerSchemaCompatibility.incompatible()`, if the new serializer class is different then the previous one.

Below is an example of how the `SimpleTypeSerializerSnapshot` is used, using Flink's `IntSerializer` as an example:

```java
public class IntSerializerSnapshot extends SimpleTypeSerializerSnapshot<Integer> {
    public IntSerializerSnapshot() {
        super(() -> IntSerializer.INSTANCE);
    }
}
```

The `IntSerializer` has no state or configurations. Serialization format is solely defined by the serializer
class itself, and can only be read by another `IntSerializer`. Therefore, it suits the use case of the
`SimpleTypeSerializerSnapshot`.

The base super constructor of the `SimpleTypeSerializerSnapshot` expects a `Supplier` of instances
of the corresponding serializer, regardless of whether the snapshot is currently being restored or being written during
snapshots. That supplier is used to create the restore serializer, as well as type checks to verify that the
new serializer is of the same expected serializer class.

### Implementing a `CompositeTypeSerializerSnapshot`

The `CompositeTypeSerializerSnapshot` is intended for serializers that rely on multiple nested serializers for serialization.

Before further explanation, we call the serializer, which relies on multiple nested serializer(s), as the "outer" serializer in this context.
Examples for this could be `MapSerializer`, `ListSerializer`, `GenericArraySerializer`, etc.
Consider the `MapSerializer`, for example - the key and value serializers would be the nested serializers,
while `MapSerializer` itself is the "outer" serializer.

In this case, the snapshot of the outer serializer should also contain snapshots of the nested serializers, so that
the compatibility of the nested serializers can be independently checked. When resolving the compatibility of the
outer serializer, the compatibility of each nested serializer needs to be considered.

`CompositeTypeSerializerSnapshot` is provided to assist in the implementation of snapshots for these kind of
composite serializers. It deals with reading and writing the nested serializer snapshots, as well as resolving
the final compatibility result taking into account the compatibility of all nested serializers.

Below is an example of how the `CompositeTypeSerializerSnapshot` is used, using Flink's `MapSerializer` as an example:

```java
public class MapSerializerSnapshot<K, V> extends CompositeTypeSerializerSnapshot<Map<K, V>, MapSerializer> {

    private static final int CURRENT_VERSION = 1;

    public MapSerializerSnapshot() {
        super(MapSerializer.class);
    }

    public MapSerializerSnapshot(MapSerializer<K, V> mapSerializer) {
        super(mapSerializer);
    }

    @Override
    public int getCurrentOuterSnapshotVersion() {
        return CURRENT_VERSION;
    }

    @Override
    protected MapSerializer createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) {
        TypeSerializer<K> keySerializer = (TypeSerializer<K>) nestedSerializers[0];
        TypeSerializer<V> valueSerializer = (TypeSerializer<V>) nestedSerializers[1];
        return new MapSerializer<>(keySerializer, valueSerializer);
    }

    @Override
    protected TypeSerializer<?>[] getNestedSerializers(MapSerializer outerSerializer) {
        return new TypeSerializer<?>[] { outerSerializer.getKeySerializer(), outerSerializer.getValueSerializer() };
    }
}
```

When implementing a new serializer snapshot as a subclass of `CompositeTypeSerializerSnapshot`,
the following three methods must be implemented:
 * `#getCurrentOuterSnapshotVersion()`: This method defines the version of
   the current outer serializer snapshot's serialized binary format.
 * `#getNestedSerializers(TypeSerializer)`: Given the outer serializer, returns its nested serializers.
 * `#createOuterSerializerWithNestedSerializers(TypeSerializer[])`:
   Given the nested serializers, create an instance of the outer serializer.

The above example is a `CompositeTypeSerializerSnapshot` where there are no extra information to be snapshotted
apart from the nested serializers' snapshots. Therefore, its outer snapshot version can be expected to never
require an uptick. Some other serializers, however, contains some additional static configuration
that needs to be persisted along with the nested component serializer. An example for this would be Flink's
`GenericArraySerializer`, which contains as configuration the class of the array element type, besides
the nested element serializer.

In these cases, an additional three methods need to be implemented on the `CompositeTypeSerializerSnapshot`:
 * `#writeOuterSnapshot(DataOutputView)`: defines how the outer snapshot information is written.
 * `#readOuterSnapshot(int, DataInputView, ClassLoader)`: defines how the outer snapshot information is read.
 * `#resolveOuterSchemaCompatibility(TypeSerializer)`: checks the compatibility based on the outer snapshot information.

By default, the `CompositeTypeSerializerSnapshot` assumes that there isn't any outer snapshot information to
read / write, and therefore have empty default implementations for the above methods. If the subclass
has outer snapshot information, then all three methods must be implemented.

Below is an example of how the `CompositeTypeSerializerSnapshot` is used for composite serializer snapshots
that do have outer snapshot information, using Flink's `GenericArraySerializer` as an example:

```java
public final class GenericArraySerializerSnapshot<C> extends CompositeTypeSerializerSnapshot<C[], GenericArraySerializer> {

    private static final int CURRENT_VERSION = 1;

    private Class<C> componentClass;

    public GenericArraySerializerSnapshot() {
        super(GenericArraySerializer.class);
    }

    public GenericArraySerializerSnapshot(GenericArraySerializer<C> genericArraySerializer) {
        super(genericArraySerializer);
        this.componentClass = genericArraySerializer.getComponentClass();
    }

    @Override
    protected int getCurrentOuterSnapshotVersion() {
        return CURRENT_VERSION;
    }

    @Override
    protected void writeOuterSnapshot(DataOutputView out) throws IOException {
        out.writeUTF(componentClass.getName());
    }

    @Override
    protected void readOuterSnapshot(int readOuterSnapshotVersion, DataInputView in, ClassLoader userCodeClassLoader) throws IOException {
        this.componentClass = InstantiationUtil.resolveClassByName(in, userCodeClassLoader);
    }

    @Override
    protected boolean resolveOuterSchemaCompatibility(GenericArraySerializer newSerializer) {
        return (this.componentClass == newSerializer.getComponentClass())
            ? OuterSchemaCompatibility.COMPATIBLE_AS_IS
            : OuterSchemaCompatibility.INCOMPATIBLE;
    }

    @Override
    protected GenericArraySerializer createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) {
        TypeSerializer<C> componentSerializer = (TypeSerializer<C>) nestedSerializers[0];
        return new GenericArraySerializer<>(componentClass, componentSerializer);
    }

    @Override
    protected TypeSerializer<?>[] getNestedSerializers(GenericArraySerializer outerSerializer) {
        return new TypeSerializer<?>[] { outerSerializer.getComponentSerializer() };
    }
}
```

There are two important things to notice in the above code snippet. First of all, since this
`CompositeTypeSerializerSnapshot` implementation has outer snapshot information that is written as part of the snapshot,
the outer snapshot version, as defined by `getCurrentOuterSnapshotVersion()`, must be upticked whenever the
serialization format of the outer snapshot information changes.

Second of all, notice how we avoid using Java serialization when writing the component class, by only writing
the classname and dynamically loading it when reading back the snapshot. Avoiding Java serialization for writing
contents of serializer snapshots is in general a good practice to follow. More details about this is covered in the
next section.

## Implementation notes and best practices

#### 1. Flink restores serializer snapshots by instantiating them with their classname

A serializer's snapshot, being the single source of truth for how a registered state was serialized, serves as an
entry point to reading state in savepoints. In order to be able to restore and access previous state, the previous state
serializer's snapshot must be able to be restored.

Flink restores serializer snapshots by first instantiating the `TypeSerializerSnapshot` with its classname (written
along with the snapshot bytes). Therefore, to avoid being subject to unintended classname changes or instantiation
failures, `TypeSerializerSnapshot` classes should:

 - avoid being implemented as anonymous classes or nested classes,
 - have a public, nullary constructor for instantiation

#### 2. Avoid sharing the same `TypeSerializerSnapshot` class across different serializers

Since schema compatibility checks goes through the serializer snapshots, having multiple serializers returning
the same `TypeSerializerSnapshot` class as their snapshot would complicate the implementation for the
`TypeSerializerSnapshot#resolveSchemaCompatibility` and `TypeSerializerSnapshot#restoreSerializer()` method.

This would also be a bad separation of concerns; a single serializer's serialization schema,
configuration, as well as how to restore it, should be consolidated in its own dedicated `TypeSerializerSnapshot` class.

#### 3. Avoid using Java serialization for serializer snapshot content

Java serialization should not be used at all when writing contents of a persisted serializer snapshot.
Take for example, a serializer which needs to persist a class of its target type as part of its snapshot.
Information about the class should be persisted by writing the class name, instead of directly serializing the class
using Java. When reading the snapshot, the class name is read, and used to dynamically load the class via the name.

This practice ensures that serializer snapshots can always be safely read. In the above example, if the type class
was persisted using Java serialization, the snapshot may no longer be readable once the class implementation has changed
and is no longer binary compatible according to Java serialization specifics.

## Migrating from deprecated serializer snapshot APIs before Flink 1.7

This section is a guide for API migration from serializers and serializer snapshots that existed before Flink 1.7.

Before Flink 1.7, serializer snapshots were implemented as a `TypeSerializerConfigSnapshot` (which is now deprecated,
and will eventually be removed in the future to be fully replaced by the new `TypeSerializerSnapshot` interface).
Moreover, the responsibility of serializer schema compatibility checks lived within the `TypeSerializer`,
implemented in the `TypeSerializer#ensureCompatibility(TypeSerializerConfigSnapshot)` method.

Another major difference between the new and old abstractions is that the deprecated `TypeSerializerConfigSnapshot`
did not have the capability of instantiating the previous serializer. Therefore, in the case where your serializer
still returns a subclass of `TypeSerializerConfigSnapshot` as its snapshot, the serializer instance itself will always
be written to savepoints using Java serialization so that the previous serializer may be available at restore time.
This is very undesirable, since whether or not restoring the job will be successful is susceptible to availability
of the previous serializer's class, or in general, whether or not the serializer instance can be read back at restore
time using Java serialization. This means that you be limited to the same serializer for your state,
and could be problematic once you want to upgrade serializer classes or perform schema migration.

To be future-proof and have flexibility to migrate your state serializers and schema, it is highly recommended to
migrate from the old abstractions. The steps to do this is as follows:

 1. Implement a new subclass of `TypeSerializerSnapshot`. This will be the new snapshot for your serializer.
 2. Return the new `TypeSerializerSnapshot` as the serializer snapshot for your serializer in the
 `TypeSerializer#snapshotConfiguration()` method.
 3. Restore the job from the savepoint that existed before Flink 1.7, and then take a savepoint again.
 Note that at this step, the old `TypeSerializerConfigSnapshot` of the serializer must still exist in the classpath,
 and the implementation for the `TypeSerializer#ensureCompatibility(TypeSerializerConfigSnapshot)` method must not be
 removed. The purpose of this process is to replace the `TypeSerializerConfigSnapshot` written in old savepoints
 with the newly implemented `TypeSerializerSnapshot` for the serializer.
 4. Once you have a savepoint taken with Flink 1.7, the savepoint will contain `TypeSerializerSnapshot` as the
 state serializer snapshot, and the serializer instance will no longer be written in the savepoint.
 At this point, it is now safe to remove all implementations of the old abstraction (remove the old
 `TypeSerializerConfigSnapshot` implementation as will as the
 `TypeSerializer#ensureCompatibility(TypeSerializerConfigSnapshot)` from the serializer).

{{< top >}}

redpajama_set_name: RedPajamaGithub


text:
layout: default
---

{{ page.title }}

{{ content }}


text:
package eu.com.cwsfe.cms.web.configuration;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CreateBucketRequest;
import eu.com.cwsfe.cms.dao.CmsGlobalParamsDAO;
import eu.com.cwsfe.cms.model.CmsGlobalParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import javax.annotation.PostConstruct;

/**
 * @author Radoslaw Osinski
 */
@Profile("tomcat-aws")
@Configuration
public class AWSClientInitializer {

    private static final Logger LOGGER = LoggerFactory.getLogger(AWSClientInitializer.class);

    private final CmsGlobalParamsDAO cmsGlobalParamsDAO;

    @Autowired
    public AWSClientInitializer(CmsGlobalParamsDAO cmsGlobalParamsDAO) {
        this.cmsGlobalParamsDAO = cmsGlobalParamsDAO;
    }

    @Bean
    public AmazonS3 getAmazonS3() {
        AmazonS3 s3client = new AmazonS3Client(new SystemPropertiesCredentialsProvider());
        s3client.setRegion(Region.getRegion(Regions.valueOf(cmsGlobalParamsDAO.getByCode("AWS_IMAGES_BUCKET_REGION").getValue())));
        return s3client;
    }

    @PostConstruct
    public void initializeRootBucket() {
        CmsGlobalParam rootBucketName = cmsGlobalParamsDAO.getByCode("AWS_CWSFE_CMS_S3_ROOT_BUCKET_NAME");
        try {
            if (!getAmazonS3().doesBucketExist(rootBucketName.getValue())) {
                getAmazonS3().createBucket(new CreateBucketRequest(rootBucketName.getValue()));
            }
        } catch (AmazonServiceException ase) {
            LOGGER.error("Problem with creating root cwsfe cms bucket", ase);
        } catch (AmazonClientException ace) {
            LOGGER.error("Problem with connecting to AWS S3", ace);
        }
    }
}


text:
package main

import (
	"encoding/json"
	"fmt"
	"html/template"
	"net/http"
)

var httpReq HttpReq

type APIHandlerStr struct {
	path string
}

func (af *APIHandlerStr) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	db := connection()
	defer db.Close()
	req, _ := find(db, af.path)
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Content-Type", req.ContentType+";charset="+req.CharSet)
	w.WriteHeader(strToInt(req.StatusCode))
	w.Write([]byte(req.Payload))
}

type HandlerFactory struct {
	handler_path string
}

func (hf *HandlerFactory) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		r.ParseForm()
		httpReq = HttpReq{ApiPath: r.FormValue("api_path"),
			ContentType: r.FormValue("content_type"),
			CharSet:     r.FormValue("char_set"),
			StatusCode:  r.FormValue("status_code"),
			Payload:     r.FormValue("payload"),
		}
		db := connection()
		defer db.Close()
		req, _ := find(db, httpReq.ApiPath)
		if req.ApiPath != "" {
			result := struct {
				Duplicate bool
				Path      string
			}{
				true,
				req.ApiPath,
			}
			data, _ := json.Marshal(result)
			w.Write(data)
			err1 := httpReq.save(db)
			if err1 != nil {
				w.Write([]byte("error!"))
				return
			}
			return
		}
		err1 := httpReq.save(db)
		if err1 != nil {
			w.Write([]byte("error!"))
			return
		}

		hf.handler_path = httpReq.ApiPath
		handler := APIHandlerStr{hf.handler_path}
		handle := fmt.Sprintf("%s", hf.handler_path)
		http.Handle(handle, &handler)
		result := struct {
			Duplicate bool
			Path      string
		}{
			false,
			r.FormValue("api_path"),
		}
		data, _ := json.Marshal(result)
		w.Write(data)
	}
}

func RootHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}

	db := connection()
	defer db.Close()
	a, err := findAll(db)
	if err != nil {
		fmt.Println("ERROR fetching data: ", err)
	}

	data := struct {
		Status  map[int]string
		ApiList []string
	}{
		HttpStatusCodes,
		a,
	}
	t, _ := template.ParseFiles("index.html")
	t.Execute(w, data)
}


text:
import { lastValueFrom } from 'rxjs';

import { getBackendSrv } from '@grafana/runtime';
import { RuleNamespace } from 'app/types/unified-alerting';
import { PromRulesResponse } from 'app/types/unified-alerting-dto';

import { getDatasourceAPIUid, GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource';

export interface FetchPromRulesFilter {
  dashboardUID: string;
  panelId?: number;
}

export interface PrometheusDataSourceConfig {
  dataSourceName: string;
}

export function prometheusUrlBuilder(dataSourceConfig: PrometheusDataSourceConfig) {
  const { dataSourceName } = dataSourceConfig;

  return {
    rules: (filter?: FetchPromRulesFilter) => {
      const searchParams = new URLSearchParams();
      const params = prepareRulesFilterQueryParams(searchParams, filter);

      return {
        url: `/api/prometheus/${getDatasourceAPIUid(dataSourceName)}/api/v1/rules`,
        params: params,
      };
    },
  };
}

export function prepareRulesFilterQueryParams(
  params: URLSearchParams,
  filter?: FetchPromRulesFilter
): Record<string, string> {
  if (filter?.dashboardUID) {
    params.set('dashboard_uid', filter.dashboardUID);
    if (filter?.panelId) {
      params.set('panel_id', String(filter.panelId));
    }
  }

  return Object.fromEntries(params);
}

export async function fetchRules(dataSourceName: string, filter?: FetchPromRulesFilter): Promise<RuleNamespace[]> {
  if (filter?.dashboardUID && dataSourceName !== GRAFANA_RULES_SOURCE_NAME) {
    throw new Error('Filtering by dashboard UID is only supported for Grafana Managed rules.');
  }

  const { url, params } = prometheusUrlBuilder({ dataSourceName }).rules(filter);

  const response = await lastValueFrom(
    getBackendSrv().fetch<PromRulesResponse>({
      url,
      params,
      showErrorAlert: false,
      showSuccessAlert: false,
    })
  ).catch((e) => {
    if ('status' in e && e.status === 404) {
      throw new Error('404 from rule state endpoint. Perhaps ruler API is not enabled?');
    }
    throw e;
  });

  const nsMap: { [key: string]: RuleNamespace } = {};
  response.data.data.groups.forEach((group) => {
    group.rules.forEach((rule) => {
      rule.query = rule.query || '';
    });
    if (!nsMap[group.file]) {
      nsMap[group.file] = {
        dataSourceName,
        name: group.file,
        groups: [group],
      };
    } else {
      nsMap[group.file].groups.push(group);
    }
  });

  return Object.values(nsMap);
}


text:
package com.sun.lwuit.io.util;

import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.io.FileSystemStorage;
import com.sun.lwuit.io.impl.IOImplementation;
import com.sun.lwuit.layouts.BorderLayout;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;

/**
 * Pluggable logging framework that allows a developer to log into storage
 * using the file connector API. It is highly recommended to use this
 * class coupled with Netbeans preprocessing tags to reduce its overhead
 * completely in runtime.
 *
 * @author Shai Almog
 */
public class Log {
    /**
     * Constant indicating the logging level Debug is the default and the lowest level
     * followed by info, warning and error
     */
    public static final int DEBUG = 1;

    /**
     * Constant indicating the logging level Debug is the default and the lowest level
     * followed by info, warning and error
     */
    public static final int INFO = 2;

    /**
     * Constant indicating the logging level Debug is the default and the lowest level
     * followed by info, warning and error
     */
    public static final int WARNING = 3;

    /**
     * Constant indicating the logging level Debug is the default and the lowest level
     * followed by info, warning and error
     */
    public static final int ERROR = 4;

    private int level = DEBUG;
    private static Log instance = new Log();
    private long zeroTime = System.currentTimeMillis();
    private Writer output;
    private boolean fileWriteEnabled = false;//System.getProperty("microedition.io.file.FileConnection.version") != null;
    private String fileURL = null;

    /**
     * Installs a log subclass that can replace the logging destination/behavior
     *
     * @param newInstance the new instance for the Log object
     */
    public static void install(Log newInstance) {
        instance = newInstance;
    }

    /**
     * Default println method invokes the print instance method, uses DEBUG level
     *
     * @param text the text to print
     */
    public static void p(String text) {
        p(text, DEBUG);
    }

    /**
     * Default println method invokes the print instance method, uses given level
     *
     * @param text the text to print
     * @param level one of DEBUG, INFO, WARNING, ERROR
     */
    public static void p(String text, int level) {
        instance.print(text, level);
    }

    /**
     * This method is a shorthand form for logThrowable
     *
     * @param t the exception
     */
    public static void e(Throwable t) {
        instance.logThrowable(t);
    }

    /**
     * Logs an exception to the log, by default print is called with the exception
     * details, on supported devices the stack trace is also physically written to
     * the log
     * @param t
     */
    protected void logThrowable(Throwable t) {
        print("Exception: " + t.getClass().getName() + " - " + t.getMessage(), ERROR);
        t.printStackTrace();
        try {
            synchronized(this) {
                Writer w = getWriter();
                IOImplementation.getInstance().printStackTraceToStream(t, w);
                w.flush();
            }
        } catch(IOException err) {
            err.printStackTrace();
        }
    }

    /**
     * Default log implementation prints to the console and the file connector
     * if applicable. Also prepends the thread information and time before
     *
     * @param text the text to print
     * @param level one of DEBUG, INFO, WARNING, ERROR
     */
    protected void print(String text, int level) {
        if(this.level > level) {
            return;
        }
        text = getThreadAndTimeStamp() + " - " + text;
        System.out.println(text);
        try {
            synchronized(this) {
                Writer w = getWriter();
                w.write(text + "\n");
                w.flush();
            }
        } catch(Throwable err) {
            err.printStackTrace();
        }
    }

    /**
     * Default method for creating the output writer into which we write, this method
     * creates a simple log file using the file connector
     *
     * @return writer object
     * @throws IOException when thrown by the connector
     */
    protected Writer createWriter() throws IOException {
        try {
            if(getFileURL() == null) {
                setFileURL("file:///" + FileSystemStorage.getInstance().getRoots()[0] + "/lwuit.log");
            }
            if(FileSystemStorage.getInstance().exists(getFileURL())) {
                return new OutputStreamWriter(FileSystemStorage.getInstance().openOutputStream(getFileURL(),
                        (int)FileSystemStorage.getInstance().getLength(getFileURL())));
            } else {
                return new OutputStreamWriter(FileSystemStorage.getInstance().openOutputStream(getFileURL()));
            }
        } catch(Exception err) {
            setFileWriteEnabled(false);
            // currently return a "dummy" writer so we won't fail on device
            return new OutputStreamWriter(new ByteArrayOutputStream());
        }
    }

    private Writer getWriter() throws IOException {
        if(output == null) {
            output = createWriter();
        }
        return output;
    }

    /**
     * Returns a simple string containing a timestamp and thread name.
     *
     * @return timestamp string for use in the log
     */
    protected String getThreadAndTimeStamp() {
        long time = System.currentTimeMillis() - zeroTime;
        long milli = time % 1000;
        time /= 1000;
        long sec = time % 60;
        time /= 60;
        long min = time % 60;
        time /= 60;
        long hour = time % 60;

        return "[" + Thread.currentThread().getName() + "] " + hour  + ":" + min + ":" + sec + "," + milli;
    }

    /**
     * Sets the logging level for printing log details, the lower the value
     * the more verbose would the printouts be
     *
     * @param level one of DEBUG, INFO, WARNING, ERROR
     */
    public static void setLevel(int level) {
        instance.level = level;
    }

    /**
     * Returns the logging level for printing log details, the lower the value
     * the more verbose would the printouts be
     *
     * @return one of DEBUG, INFO, WARNING, ERROR
     */
    public static int getLevel() {
        return instance.level;
    }

    /**
     * Returns the contents of the log as a single long string to be displayed by
     * the application any way it sees fit
     *
     * @return string containing the whole log
     */
    public static String getLogContent() {
        try {
            String text = "";
            if(instance.isFileWriteEnabled()) {
                if(instance.getFileURL() == null) {
                    instance.setFileURL("file:///" + FileSystemStorage.getInstance().getRoots()[0] + "/lwuit.log");
                }
                Reader r = new InputStreamReader(FileSystemStorage.getInstance().openInputStream(instance.getFileURL()));
                char[] buffer = new char[1024];
                int size = r.read(buffer);
                while(size > -1) {
                    text += new String(buffer, 0, size);
                    size = r.read(buffer);
                }
                r.close();
            }
            return text;
        } catch (Exception ex) {
            ex.printStackTrace();
            return "";
        }
    }

    /**
     * Places a form with the log as a TextArea on the screen, this method can
     * be attached to appear at a given time or using a fixed global key. Using
     * this method might cause a problem with further log output
     */
    public static void showLog() {
        try {
            String text = getLogContent();
            TextArea area = new TextArea(text, 5, 20);
            Form f = new Form("Log");
            f.setScrollable(false);
            final Form current = Display.getInstance().getCurrent();
            Command back = new Command("Back") {
                public void actionPerformed(ActionEvent ev) {
                    current.show();
                }
            };
            f.addCommand(back);
            f.setBackCommand(back);
            f.setLayout(new BorderLayout());
            f.addComponent(BorderLayout.CENTER, area);
            f.show();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * Returns the singleton instance of the log
     *
     * @return the singleton instance of the log
     */
    public static Log getInstance() {
        return instance;
    }

    /**
     * Indicates whether GCF's file writing should be used to generate the log file
     *
     * @return the fileWriteEnabled
     */
    public boolean isFileWriteEnabled() {
        return fileWriteEnabled;
    }

    /**
     * Indicates whether GCF's file writing should be used to generate the log file
     *
     * @param fileWriteEnabled the fileWriteEnabled to set
     */
    public void setFileWriteEnabled(boolean fileWriteEnabled) {
        this.fileWriteEnabled = fileWriteEnabled;
    }

    /**
     * Indicates the URL where the log file is saved
     *
     * @return the fileURL
     */
    public String getFileURL() {
        return fileURL;
    }

    /**
     * Indicates the URL where the log file is saved
     *
     * @param fileURL the fileURL to set
     */
    public void setFileURL(String fileURL) {
        this.fileURL = fileURL;
    }

    /**
     * Activates the filesystem tracking of file open/close operations
     */
    public void trackFileSystem() {
        IOImplementation.getInstance().setLogListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                String s = (String)evt.getSource();
                // don't log the creation of the log itself
                if(output != null) {
                    p(s);
                }
            }
        });
    }
}


text:
<?php

namespace Orukusaki\TwiML\Voice\Verb;

use Orukusaki\TwiML\Node;

/**
 * Class Pause
 * @package Orukusaki\TwiML\Verb
 * @see https://www.twilio.com/docs/api/twiml/pause
 */
class Pause extends Node
{
    public function withLength($length)
    {
        $this->attributes['length'] = $length;

        return $this;
    }
}


text:
module Azure::Labservices::Mgmt::V2018_10_15
  module Models
    #
    # The object that describes the operations
    #
    class OperationMetadataDisplay

      include MsRestAzure

      # @return [String] Friendly name of the resource provider
      attr_accessor :provider

      # @return [String] Resource type on which the operation is performed.
      attr_accessor :resource

      # @return [String] Operation type: read, write, delete, listKeys/action,
      # etc.
      attr_accessor :operation

      # @return [String] Friendly name of the operation
      attr_accessor :description

      #
      # Mapper for OperationMetadataDisplay class as Ruby Hash.
      # This will be used for serialization/deserialization.
      #
      def self.mapper()
        {
          client_side_validation: true,
          required: false,
          serialized_name: 'OperationMetadataDisplay',
          type: {
            name: 'Composite',
            class_name: 'OperationMetadataDisplay',
            model_properties: {
              provider: {
                client_side_validation: true,
                required: false,
                serialized_name: 'provider',
                type: {
                  name: 'String'
                }
              },
              resource: {
                client_side_validation: true,
                required: false,
                serialized_name: 'resource',
                type: {
                  name: 'String'
                }
              },
              operation: {
                client_side_validation: true,
                required: false,
                serialized_name: 'operation',
                type: {
                  name: 'String'
                }
              },
              description: {
                client_side_validation: true,
                required: false,
                serialized_name: 'description',
                type: {
                  name: 'String'
                }
              }
            }
          }
        }
      end
    end
  end
end


text:
<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright 2005-2011 The Kuali Foundation

    Licensed under the Educational Community License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.opensource.org/licenses/ecl2.php

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<data xmlns="ns:workflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="ns:workflow resource:WorkflowData">
  <ruleTemplates xmlns="ns:workflow/RuleTemplate" xsi:schemaLocation="ns:workflow/RuleTemplate resource:RuleTemplate">
    <ruleTemplate>
      <name>AffirmativeActionOfficer</name>
      <description>Office Of Affirmative Action Officer</description>
    </ruleTemplate>
  </ruleTemplates>
</data>


text:
package org.jsimpledb.kv.raft;

import com.google.common.collect.Iterables;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.jsimpledb.kv.KeyRange;
import org.jsimpledb.kv.RetryTransactionException;
import org.jsimpledb.kv.mvcc.Mutations;
import org.jsimpledb.kv.mvcc.Writes;
import org.jsimpledb.kv.raft.msg.AppendRequest;
import org.jsimpledb.kv.raft.msg.AppendResponse;
import org.jsimpledb.kv.raft.msg.CommitRequest;
import org.jsimpledb.kv.raft.msg.CommitResponse;
import org.jsimpledb.kv.raft.msg.GrantVote;
import org.jsimpledb.kv.raft.msg.InstallSnapshot;
import org.jsimpledb.kv.raft.msg.Message;
import org.jsimpledb.kv.raft.msg.PingRequest;
import org.jsimpledb.kv.raft.msg.PingResponse;
import org.jsimpledb.kv.raft.msg.RequestVote;
import org.jsimpledb.util.LongEncoder;
import org.slf4j.Logger;

/**
 * Common superclass for the three roles played by a Raft node:
 * {@linkplain LeaderRole leader}, {@linkplain FollowerRole follower}, and {@linkplain CandidateRole candidate}.
 */
public abstract class Role {

    final Logger log;
    final RaftKVDatabase raft;
    final Service checkReadyTransactionsService = new Service(this, "check ready transactions") {
        @Override
        public void run() {
            Role.this.checkReadyTransactions();
        }
    };
    final Service checkWaitingTransactionsService = new Service(this, "check waiting transactions") {
        @Override
        public void run() {
            Role.this.checkWaitingTransactions();
        }
    };
    final Service applyCommittedLogEntriesService = new Service(this, "apply committed logs") {
        @Override
        public void run() {
            Role.this.applyCommittedLogEntries();
        }
    };
    final Service triggerKeyWatchesService = new Service(this, "trigger key watches") {
        @Override
        public void run() {
            Role.this.triggerKeyWatches();
        }
    };

// Constructors

    Role(RaftKVDatabase raft) {
        this.raft = raft;
        this.log = this.raft.log;
        assert Thread.holdsLock(this.raft);
    }

// Status

    /**
     * Get the {@link RaftKVDatabase} with which this instance is associated.
     *
     * @return associated database
     */
    public RaftKVDatabase getKVDatabase() {
        return this.raft;
    }

// Lifecycle

    void setup() {
        assert Thread.holdsLock(this.raft);
        this.raft.requestService(this.checkReadyTransactionsService);
        this.raft.requestService(this.checkWaitingTransactionsService);
        this.raft.requestService(this.applyCommittedLogEntriesService);
    }

    void shutdown() {
        assert Thread.holdsLock(this.raft);
        for (RaftKVTransaction tx : this.raft.openTransactions.values())
            this.cleanupForTransaction(tx);
    }

// Service

    abstract void outputQueueEmpty(String address);

    /**
     * Check transactions in the {@link TxState#COMMIT_READY} state to see if we can advance them.
     */
    void checkReadyTransactions() {
        for (RaftKVTransaction tx : new ArrayList<RaftKVTransaction>(this.raft.openTransactions.values()))
            new CheckReadyTransactionService(this, tx).run();
    }

    /**
     * Check transactions in the {@link TxState#COMMIT_WAITING} state to see if they are committed yet.
     * We invoke this service method whenever our {@code commitIndex} advances.
     */
    void checkWaitingTransactions() {
        for (RaftKVTransaction tx : new ArrayList<RaftKVTransaction>(this.raft.openTransactions.values()))
            new CheckWaitingTransactionService(this, tx).run();
    }

    /**
     * Apply committed but unapplied log entries to the state machine.
     * We invoke this service method whenever log entries are added or our {@code commitIndex} advances.
     */
    void applyCommittedLogEntries() {

        // Apply committed log entries to the state machine
        while (this.raft.lastAppliedIndex < this.raft.commitIndex) {

            // Grab the first unwritten log entry
            final LogEntry logEntry = this.raft.raftLog.get(0);
            assert logEntry.getIndex() == this.raft.lastAppliedIndex + 1;

            // Check with subclass
            if (!this.mayApplyLogEntry(logEntry))
                break;

            // Get the current config as of the log entry we're about to apply
            final HashMap<String, String> logEntryConfig = new HashMap<>(this.raft.lastAppliedConfig);
            logEntry.applyConfigChange(logEntryConfig);

            // Prepare combined Mutations containing prefixed log entry changes plus my own
            final Writes logWrites = logEntry.getWrites();
            final Writes myWrites = new Writes();
            myWrites.getPuts().put(RaftKVDatabase.LAST_APPLIED_TERM_KEY, LongEncoder.encode(logEntry.getTerm()));
            myWrites.getPuts().put(RaftKVDatabase.LAST_APPLIED_INDEX_KEY, LongEncoder.encode(logEntry.getIndex()));
            myWrites.getPuts().put(RaftKVDatabase.LAST_APPLIED_CONFIG_KEY, this.raft.encodeConfig(logEntryConfig));
            final byte[] stateMachinePrefix = this.raft.getStateMachinePrefix();
            final Mutations mutations = new Mutations() {

                @Override
                public Iterable<KeyRange> getRemoveRanges() {
                    return Iterables.transform(logWrites.getRemoveRanges(), new PrefixKeyRangeFunction(stateMachinePrefix));
                }

                @Override
                public Iterable<Map.Entry<byte[], byte[]>> getPutPairs() {
                    return Iterables.concat(
                      Iterables.transform(logWrites.getPutPairs(), new PrefixPutFunction(stateMachinePrefix)),
                      myWrites.getPutPairs());
                }

                @Override
                public Iterable<Map.Entry<byte[], Long>> getAdjustPairs() {
                    return Iterables.transform(logWrites.getAdjustPairs(), new PrefixAdjustFunction(stateMachinePrefix));
                }
            };

            // Apply updates to the key/value store (durably)
            if (this.log.isDebugEnabled())
                this.debug("applying committed log entry " + logEntry + " to key/value store");
            try {
                this.raft.kv.mutate(mutations, true);
            } catch (Exception e) {
                if (e instanceof RuntimeException && e.getCause() instanceof IOException)
                    e = (IOException)e.getCause();
                this.error("error applying log entry " + logEntry + " to key/value store", e);
                break;
            }

            // Update in-memory state
            this.raft.lastAppliedTerm = logEntry.getTerm();
            assert logEntry.getIndex() == this.raft.lastAppliedIndex + 1;
            this.raft.lastAppliedIndex = logEntry.getIndex();
            logEntry.applyConfigChange(this.raft.lastAppliedConfig);
            assert this.raft.currentConfig.equals(this.raft.buildCurrentConfig());

            // Delete the log entry
            this.raft.raftLog.remove(0);
            if (!logEntry.getFile().delete())
                this.error("failed to delete log file " + logEntry.getFile());
        }
    }

    /**
     * Determine whether the given log entry may be applied to the state machine.
     */
    boolean mayApplyLogEntry(LogEntry logEntry) {
        return true;
    }

    /**
     * Trigger any key watches for changes in log entries committed since the last time we checked.
     *
     *

     * This should be invoked:
     *

     *
After advancing the commitIndex

     *
After resetting the state machine

     *
After installing a snapshot

     *

     */
    void triggerKeyWatches() {

        // Sanity check
        assert this.raft.commitIndex >= this.raft.lastAppliedIndex;
        assert this.raft.commitIndex <= this.raft.lastAppliedIndex + this.raft.raftLog.size();
        assert this.raft.keyWatchIndex <= this.raft.commitIndex;

        // If we have recevied a snapshot install, we may not be able to tell which keys have changed since last notification;
        // in that case, trigger all key watches; otherwise, trigger the keys affected by newly committed log entries
        if (this.raft.keyWatchIndex < this.raft.lastAppliedIndex) {
            this.raft.keyWatchTracker.triggerAll();
            this.raft.keyWatchIndex = this.raft.commitIndex;
        } else {
            while (this.raft.keyWatchIndex < this.raft.commitIndex)
                this.raft.keyWatchTracker.trigger(this.raft.getLogEntryAtIndex(++this.raft.keyWatchIndex).getWrites());
        }
    }

// Transactions

    /**
     * Check a transaction that is ready to be committed (in the {@link TxState#COMMIT_READY} state).
     *
     *

     * This should be invoked:
     *

     *
After changing roles

     *
After a transaction has entered the {@link TxState#COMMIT_READY} state

     *
After the leader is newly known (in {@link FollowerRole})

     *
After the leader's output queue goes from non-empty to empty (in {@link FollowerRole})

     *
After the leader's {@code commitIndex} has advanced, in case a config change transaction
     *      is waiting on a previous config change transaction (in {@link LeaderRole})

     *

     *
     * @param tx the transaction
     * @throws KVTransactionException if an error occurs
     */
    void checkReadyTransaction(RaftKVTransaction tx) {

        // Get transaction mutations
        final Writes writes = tx.getMutableView().getWrites();
        final String[] configChange = tx.getConfigChange();

        // Determine whether transaction is truly read-only
        final boolean readOnly = tx.isReadOnly() || (writes.isEmpty() && configChange == null);

        // No need to talk to leader for read-only transactions unless LINEARIZABLE
        if (readOnly) {
            switch (tx.getConsistency()) {
            case UNCOMMITTED:
                if (this.log.isTraceEnabled())
                    this.trace("trivial commit for read-only, UNCOMMITTED " + tx);
                this.raft.succeed(tx);
                return;
            case EVENTUAL:
                this.advanceReadyTransaction(tx, tx.getBaseTerm(), tx.getBaseIndex());
                return;
            default:
                break;
            }
        }

        // Requires leader communication - let subclass handle it
        this.checkReadyLeaderTransaction(tx, readOnly);
    }

    /**
     * Check a transaction that is ready to be committed (in the {@link TxState#COMMIT_READY} state)
     * and requires communication with the leader.
     *
     * @param tx the transaction
     * @param readOnly if transaction is read-only
     * @throws KVTransactionException if an error occurs
     */
    abstract void checkReadyLeaderTransaction(RaftKVTransaction tx, boolean readOnly);

    /**
     * Advance a transaction from the {@link TxState#COMMIT_READY} state to the {@link TxState#COMMIT_WAITING} state.
     *
     * @param tx the transaction
     */
    void advanceReadyTransaction(RaftKVTransaction tx, long commitTerm, long commitIndex) {

        // Sanity check
        assert tx.getState().equals(TxState.COMMIT_READY);

        // Set commit term & index and update state
        if (this.log.isDebugEnabled())
            this.debug("advancing " + tx + " to " + TxState.COMMIT_WAITING + " with commit " + commitIndex + "t" + commitTerm);
        tx.setCommitTerm(commitTerm);
        tx.setCommitIndex(commitIndex);
        tx.setState(TxState.COMMIT_WAITING);

        // Discard information we no longer need
        tx.getMutableView().disableReadTracking();

        // Check this transaction to see if it can be committed
        this.raft.requestService(this.checkWaitingTransactionsService);
    }

    /**
     * Check a transaction waiting for its log entry to be committed (in the {@link TxState#COMMIT_WAITING} state).
     *
     *

     * This should be invoked:
     *

     *
After changing roles

     *
After a transaction has entered the {@link TxState#COMMIT_WAITING} state

     *
After advancing my {@code commitIndex} (as leader or follower)

     *
After receiving an updated {@linkplain AppendResponse#getLeaderLeaseTimeout leader lease timeout}
     *      (in {@link FollowerRole})

     *

     *
     * @param tx the transaction
     * @throws KVTransactionException if an error occurs
     */
    void checkWaitingTransaction(RaftKVTransaction tx) {

        // Handle the case the transaction's committed log index has already been applied to the state machine
        final long commitIndex = tx.getCommitIndex();
        if (commitIndex < this.raft.lastAppliedIndex) {

            // This can happen if we lose contact and by the time we're back the log entry has
            // already been applied to the state machine on some leader and that leader sent
            // use an InstallSnapshot message. We don't know whether it actually got committed
            // or not, so the transaction must be retried.
            throw new RetryTransactionException(tx, "committed log entry was missed");
        }

        // Has the transaction's log entry been received and committed yet?
        if (commitIndex > this.raft.commitIndex)
            return;

        // Verify the term of the committed log entry; if not what we expect, the log entry was overwritten by a new leader
        final long commitTerm = tx.getCommitTerm();
        if (this.raft.getLogTermAtIndex(commitIndex) != commitTerm)
            throw new RetryTransactionException(tx, "leader was deposed during commit and transaction's log entry overwritten");

        // Check with subclass
        if (!this.mayCommit(tx))
            return;

        // Transaction is officially committed now
        if (this.log.isTraceEnabled())
            this.trace("commit successful for " + tx + " (commit index " + this.raft.commitIndex + " >= " + commitIndex + ")");
        this.raft.succeed(tx);
    }

    boolean mayCommit(RaftKVTransaction tx) {
        return true;
    }

    /**
     * Perform any role-specific transaction cleanups.
     *
     *

     * Invoked either when transaction is closed or this role is being shutdown.
     *
     *

     * The implementation in {@link Role} does nothing; subclasses should override if appropriate.
     *
     * @param tx the transaction
     */
    void cleanupForTransaction(RaftKVTransaction tx) {
    }

// Messages

    // This is a package access version of "implements MessageSwitch"
    abstract void caseAppendRequest(AppendRequest msg);
    abstract void caseAppendResponse(AppendResponse msg);
    abstract void caseCommitRequest(CommitRequest msg);
    abstract void caseCommitResponse(CommitResponse msg);
    abstract void caseGrantVote(GrantVote msg);
    abstract void caseInstallSnapshot(InstallSnapshot msg);
    abstract void caseRequestVote(RequestVote msg);

    void casePingRequest(PingRequest msg) {
        this.raft.sendMessage(new PingResponse(this.raft.clusterId,
          this.raft.identity, msg.getSenderId(), this.raft.currentTerm, msg.getTimestamp()));
    }

    void casePingResponse(PingResponse msg) {
        // ignore by default
    }

    boolean mayAdvanceCurrentTerm(Message msg) {
        return true;
    }

    void failUnexpectedMessage(Message msg) {
        this.warn("rec'd unexpected message " + msg + " while in role " + this + "; ignoring");
    }

// Debug

    boolean checkState() {
        return true;
    }

// Logging

    void trace(String msg, Throwable t) {
        this.raft.trace(msg, t);
    }

    void trace(String msg) {
        this.raft.trace(msg);
    }

    void debug(String msg, Throwable t) {
        this.raft.debug(msg, t);
    }

    void debug(String msg) {
        this.raft.debug(msg);
    }

    void info(String msg, Throwable t) {
        this.raft.info(msg, t);
    }

    void info(String msg) {
        this.raft.info(msg);
    }

    void warn(String msg, Throwable t) {
        this.raft.warn(msg, t);
    }

    void warn(String msg) {
        this.raft.warn(msg);
    }

    void error(String msg, Throwable t) {
        this.raft.error(msg, t);
    }

    void error(String msg) {
        this.raft.error(msg);
    }

// Object

    @Override
    public abstract String toString();

    String toStringPrefix() {
        return this.getClass().getSimpleName()
          + "[term=" + this.raft.currentTerm
          + ",applied=" + this.raft.lastAppliedIndex + "t" + this.raft.lastAppliedTerm
          + ",commit=" + this.raft.commitIndex
          + ",log=" + this.raft.raftLog
          + "]";
    }
}


text:
//
//  JXActivitySearchViewController.h
//  FishingWorld
//
//  Created by mac on 17/3/24.
//  Copyright © 2017年 zhuya. All rights reserved.
//

#import <UIKit/UIKit.h>

/**
 活动搜索控制器
 */
@interface JXActivitySearchViewController : UIViewController

@end


text:
package com.example.bigquery;

// [START bigquery_create_routine]
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.RoutineArgument;
import com.google.cloud.bigquery.RoutineId;
import com.google.cloud.bigquery.RoutineInfo;
import com.google.cloud.bigquery.StandardSQLDataType;
import com.google.cloud.bigquery.StandardSQLTypeName;
import com.google.common.collect.ImmutableList;

// Sample to create a routine
public class CreateRoutine {

  public static void main(String[] args) {
    // TODO(developer): Replace these variables before running the sample.
    String datasetName = "MY_DATASET_NAME";
    String routineName = "MY_ROUTINE_NAME";
    createRoutine(datasetName, routineName);
  }

  public static void createRoutine(String datasetName, String routineName) {
    try {
      // Initialize client that will be used to send requests. This client only needs to be created
      // once, and can be reused for multiple requests.
      BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

      RoutineId routineId = RoutineId.of(datasetName, routineName);

      RoutineInfo routineInfo =
          RoutineInfo.newBuilder(routineId)
              .setRoutineType("SCALAR_FUNCTION")
              .setLanguage("SQL")
              .setBody("x * 3")
              .setArguments(
                  ImmutableList.of(
                      RoutineArgument.newBuilder()
                          .setName("x")
                          .setDataType(
                              StandardSQLDataType.newBuilder(StandardSQLTypeName.INT64).build())
                          .build()))
              .build();
      bigquery.create(routineInfo);
      System.out.println("Routine created successfully");
    } catch (BigQueryException e) {
      System.out.println("Routine was not created. \n" + e.toString());
    }
  }
}
// [END bigquery_create_routine]


text:
<?php

namespace PiApp\AdminBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use PiApp\AdminBundle\Repository\PageRepository;
use Doctrine\ORM\EntityRepository;

/**
 * Description of the PageByTransType form.
 *
 * @category   Admin_Form
 * @package    CMS_Form
 *
 * @author Etienne de Longeaux <etienne.delongeaux@gmail.com>
 */
class PageByTransType extends AbstractType
{
    /**
     * @var array
     */
    protected $_roles_user;

    /**
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
     */
    protected $_container;

    /**
     * @var string
     */
    protected $_locale;

    /**
     * Constructor.
     *
     * @param array $roles_user
     * @return void
     */
    public function __construct($locale, $roles_user = array('ROLE_ADMIN', 'ROLE_SUPER_ADMIN', 'ROLE_CONTENT_MANAGER'), ContainerInterface $container)
    {
        $this->_roles_user     = $roles_user;
        $this->_container     = $container;
        $this->_locale        = $locale;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if (in_array('ROLE_ADMIN', $this->_roles_user) || in_array('ROLE_SUPER_ADMIN', $this->_roles_user) || in_array('ROLE_CONTENT_MANAGER', $this->_roles_user))
            $read_only = false;
        else
            $read_only = true;

        $builder
            ->add('enabled', 'checkbox', array(
                    'data'  => true,
                    'label'    => 'pi.form.label.field.enabled',
            ))
            ->add('user', 'entity', array(
                    'class'     => 'BootStrapUserBundle:User',
                    'read_only'    => $read_only,
                    'label'    => 'pi.form.label.field.user',
                    "attr"         => array(
                            "class"=>"pi_simpleselect",
                    ),
            ))
            ->add('rubrique', 'entity', array(
                    'class' => 'PiAppAdminBundle:Rubrique',
                    'query_builder' => function(EntityRepository $er) {
                        return $er->getAllPageRubrique();
                    },
                    'property' => 'titre',
                    'empty_value' => 'pi.form.label.select.choose.option',
                    'label'     => 'pi.page.form.rubrique',
                    'multiple'    => false,
                    'required'  => false,
                    "attr" => array(
                            "class"=>"pi_simpleselect",
                    ),
            ))
            ->add('layout', 'entity', array(
                    'class' => 'PiAppAdminBundle:Layout',
                    'label'     => 'pi.page.form.layout',
                    "attr" => array(
                            "class"=>"pi_simpleselect",
                    ),
            ))
            ->add('page_css', 'entity', array(
                    'class' => 'PiAppAdminBundle:Page',
                    'query_builder' => function(EntityRepository $er) {
                        return $er->getAllPageCss();
                    },
                    'property' => 'url',
                    'multiple'    => true,
                    'required'  => false,
                    'empty_value' => 'pi.form.label.select.choose.option',
                    'label'     => 'pi.page.form.page_css',
                    "attr" => array(
                            "class"=>"pi_multiselect",
                    ),
            ))
            ->add('page_js', 'entity', array(
                    'class' => 'PiAppAdminBundle:Page',
                    'query_builder' => function(EntityRepository $er) {
                        return $er->getAllPageJs();
                    },
                    'property' => 'url',
                    'multiple'    => true,
                    'required'  => false,
                    'empty_value' => 'pi.form.label.select.choose.option',
                    'label'     => 'pi.page.form.page_js',
                    "attr" => array(
                            "class"=>"pi_multiselect",
                    ),
            ))
            ->add('keywords', 'entity', array(
                    'class' => 'PiAppAdminBundle:KeyWord',
                    'query_builder' => function(EntityRepository $er) {
                        return $er->getAllPageKeyWords();
                    },
                    'multiple'    => true,
                    'required'  => false,
                    'empty_value' => 'pi.form.label.select.choose.option',
                    'label'     => 'pi.page.form.keywords',
                    "attr" => array(
                            "class"=>"pi_multiselect",
                    ),
            ))
            ->add('meta_content_type', 'hidden')
            ->add('cacheable', 'checkbox', array(
                    'label'     => 'pi.page.form.cacheable',
                    'required'  => false,
                    //'help_block' => 'Returns a 304 "not modified" status, when the template has not changed since last visit.',
                    'help_block' => $this->_container->get('translator')->trans('pi.page.form.field.cacheable'),
            ))
            ->add('public', 'checkbox', array(
                    'label'     => 'pi.page.form.public',
                    'required'  => false,
                    //'help_block' => 'Allows proxies to cache the same content for different visitors.'
                    'help_block' => $this->_container->get('translator')->trans('pi.page.form.field.public'),
            ))
            ->add('lifetime', 'number', array(
                    'label'     => 'pi.page.form.lifetime',
                    'required'  => false,
                    //'help_block' => 'Does a full content caching during the specified lifetime. Leave empty for no cache.'
                    'help_block' => $this->_container->get('translator')->trans('pi.page.form.field.lifetime'),
            ))
            ->add('route_name', 'text', array(
                    'label'    => 'pi.page.form.route_name'
            ))
            ->add('url', 'text', array(
                    'label'    => 'pi.page.form.url'
            ))
            ->add('translations', 'collection', array(
                    'allow_add' => true,
                    'allow_delete' => true,
                    'prototype'    => true,
                    // Post update
                    'by_reference' => true,
                    'type'   => new TranslationPageType($this->_locale, $this->_container),
                    'options'  => array(
                            'attr'      => array('class' => 'translation_widget')
                    ),
                    'label'    => ' '
            ))
         ;
    }

    public function getName()
    {
        return 'piapp_adminbundle_pagetype';
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
                'data_class' => 'PiApp\AdminBundle\Entity\Page',
        ));
    }

}


text:
var express = require('express'),
    models = require('./psql_handlers'),
    app = express();

app.set('port', process.env.PORT || 8000);

app.get('/psql/select', models.psqSelectAll);

app.listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));
});


text:
DIR=	seed
TOP=	../..
CC=	cc
CPP=	$(CC) -E
INCLUDES=
CFLAG=-g
MAKEFILE=	Makefile
AR=		ar r

CFLAGS= $(INCLUDES) $(CFLAG)

GENERAL=Makefile
TEST=
APPS=

LIB=$(TOP)/libcrypto.a
LIBSRC=seed.c seed_ecb.c seed_cbc.c seed_cfb.c seed_ofb.c
LIBOBJ=seed.o seed_ecb.o seed_cbc.o seed_cfb.o seed_ofb.o

SRC= $(LIBSRC)

EXHEADER= seed.h
HEADER= seed_locl.h $(EXHEADER)

ALL=    $(GENERAL) $(SRC) $(HEADER)

top:
	(cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)

all:	lib

lib:	$(LIBOBJ)
	$(AR) $(LIB) $(LIBOBJ)
	$(RANLIB) $(LIB) || echo Never mind.
	@touch lib

files:
	$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO

links:
	@$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
	@$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
	@$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)

install:
	@[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
	@headerlist="$(EXHEADER)"; for i in $$headerlist ; \
	do  \
	(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
	chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
	done;

tags:
	ctags $(SRC)

tests:

lint:
	lint -DLINT $(INCLUDES) $(SRC)>fluff

update: depend

depend:
	@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
	$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)

dclean:
	$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
	mv -f Makefile.new $(MAKEFILE)

clean:
	rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff

# DO NOT DELETE THIS LINE -- make depend depends on it.

seed.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
seed.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
seed.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
seed.o: ../../include/openssl/seed.h ../../include/openssl/stack.h
seed.o: ../../include/openssl/symhacks.h c:\mingw\include\_mingw.h
seed.o: c:\mingw\include\memory.h c:\mingw\include\stdio.h
seed.o: c:\mingw\include\stdlib.h c:\mingw\include\string.h
seed.o: c:\mingw\include\sys\types.h
seed.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stdarg.h
seed.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stddef.h seed.c seed_locl.h
seed_cbc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
seed_cbc.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h
seed_cbc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
seed_cbc.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
seed_cbc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
seed_cbc.o: c:\mingw\include\_mingw.h c:\mingw\include\stdio.h
seed_cbc.o: c:\mingw\include\stdlib.h c:\mingw\include\sys\types.h
seed_cbc.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stdarg.h
seed_cbc.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stddef.h seed_cbc.c
seed_cfb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
seed_cfb.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h
seed_cfb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
seed_cfb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
seed_cfb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
seed_cfb.o: c:\mingw\include\_mingw.h c:\mingw\include\stdio.h
seed_cfb.o: c:\mingw\include\stdlib.h c:\mingw\include\sys\types.h
seed_cfb.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stdarg.h
seed_cfb.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stddef.h seed_cfb.c
seed_ecb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
seed_ecb.o: ../../include/openssl/opensslconf.h
seed_ecb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
seed_ecb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
seed_ecb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
seed_ecb.o: c:\mingw\include\_mingw.h c:\mingw\include\stdio.h
seed_ecb.o: c:\mingw\include\stdlib.h c:\mingw\include\sys\types.h
seed_ecb.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stdarg.h
seed_ecb.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stddef.h seed_ecb.c
seed_ofb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
seed_ofb.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h
seed_ofb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
seed_ofb.o: ../../include/openssl/safestack.h ../../include/openssl/seed.h
seed_ofb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
seed_ofb.o: c:\mingw\include\_mingw.h c:\mingw\include\stdio.h
seed_ofb.o: c:\mingw\include\stdlib.h c:\mingw\include\sys\types.h
seed_ofb.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stdarg.h
seed_ofb.o: c:\mingw\lib\gcc\mingw32\4.8.1\include\stddef.h seed_ofb.c


text:
/*
 *  The server_version is a character string containing three decimal numbers
 *  separated by periods:
 *
 *      <major>.<minor>.<release>
 *
 *  The major version number changes very slowly, only when existing MOO code
 *  might stop working, due to an incompatible change in the syntax or
 *  semantics of the programming language, or when an incompatible change is
 *  made to the database format.
 *
 *  The minor version number changes more quickly, whenever an upward-
 *  compatible change is made in the programming language syntax or semantics.
 *  The most common cause of this is the addition of a new kind of expression,
 *  statement, or built-in function.
 *
 *  The release version number changes as frequently as bugs are fixed in the
 *  server code.  Changes in the release number indicate changes that should
 *  only be visible to users as bug fixes, if at all.
 *
 */

#include "config.h"
#include "version.h"

const char *server_version = "1.8.1";

int
check_version(DB_Version version)
{
    return version < Num_DB_Versions;
}

char rcsid_version[] = "$Id: version.c,v 1.10 2000/01/11 02:15:09 nop Exp $";


text:
require('babel-core/register')({
  stage: 0
})


text:
<?php declare(strict_types=1);

namespace Darvin\ImageBundle\Imagine\Cache\Warmer;

use Darvin\ImageBundle\Entity\Image\AbstractImage;
use Doctrine\ORM\EntityManager;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
use Vich\UploaderBundle\Mapping\PropertyMappingFactory;
use Vich\UploaderBundle\Storage\StorageInterface;

/**
 * Imagine cache warmer
 */
class ImagineCacheWarmer implements ImagineCacheWarmerInterface
{
    /**
     * @var \Doctrine\ORM\EntityManager
     */
    private $em;

    /**
     * @var \Liip\ImagineBundle\Imagine\Cache\CacheManager
     */
    private $imagineCacheManager;

    /**
     * @var \Liip\ImagineBundle\Imagine\Data\DataManager
     */
    private $imagineDataManager;

    /**
     * @var \Liip\ImagineBundle\Imagine\Filter\FilterManager
     */
    private $imagineFilterManager;

    /**
     * @var \Vich\UploaderBundle\Mapping\PropertyMappingFactory
     */
    private $uploaderMappingFactory;

    /**
     * @var \Vich\UploaderBundle\Storage\StorageInterface
     */
    private $uploaderStorage;

    /**
     * @var array
     */
    private $imagineFilterSets;

    /**
     * @param \Doctrine\ORM\EntityManager                         $em                     Entity manager
     * @param \Liip\ImagineBundle\Imagine\Cache\CacheManager      $imagineCacheManager    Imagine cache manager
     * @param \Liip\ImagineBundle\Imagine\Data\DataManager        $imagineDataManager     Imagine data manager
     * @param \Liip\ImagineBundle\Imagine\Filter\FilterManager    $imagineFilterManager   Imagine filter manager
     * @param \Vich\UploaderBundle\Mapping\PropertyMappingFactory $uploaderMappingFactory Uploader property mapping factory
     * @param \Vich\UploaderBundle\Storage\StorageInterface       $uploaderStorage        Uploader storage
     * @param array                                               $imagineFilterSets      Imagine filter sets
     */
    public function __construct(
        EntityManager $em,
        CacheManager $imagineCacheManager,
        DataManager $imagineDataManager,
        FilterManager $imagineFilterManager,
        PropertyMappingFactory $uploaderMappingFactory,
        StorageInterface $uploaderStorage,
        array $imagineFilterSets
    ) {
        $this->em = $em;
        $this->imagineCacheManager = $imagineCacheManager;
        $this->imagineDataManager = $imagineDataManager;
        $this->imagineFilterManager = $imagineFilterManager;
        $this->uploaderMappingFactory = $uploaderMappingFactory;
        $this->uploaderStorage = $uploaderStorage;
        $this->imagineFilterSets = $imagineFilterSets;
    }

    /**
     * {@inheritDoc}
     */
    public function warmImageCache(AbstractImage $image): void
    {
        if ($image->isVector()) {
            return;
        }

        $filters = [];

        foreach ($this->imagineFilterSets as $filter => $options) {
            if (!isset($options['entities'])) {
                continue;
            }
            foreach ((array)$options['entities'] as $entity) {
                if ($image instanceof $entity) {
                    $filters[] = $filter;
                }
            }
        }

        // Remove old cached images if filename changed
        $changeSet = $this->em->getUnitOfWork()->getEntityChangeSet($image);

        if (isset($changeSet['filename']) && null !== $changeSet['filename'][0]) {
            $mapping = $this->uploaderMappingFactory->fromField($image, AbstractImage::PROPERTY_FILE, AbstractImage::class);
            $uploadDir = $mapping->getUploadDir($image);
            $uploadDir = null !== $uploadDir ? str_replace('\\', '/', $uploadDir).'/' : '';
            $pathname = $mapping->getUriPrefix().'/'.$uploadDir.$changeSet['filename'][0];

            foreach (array_keys($this->imagineFilterManager->getFilterConfiguration()->all()) as $filter) {
                if (!isset($this->imagineFilterSets[$filter]) && $this->imagineCacheManager->isStored($pathname, $filter)) {
                    $filters[] = $filter;
                }
            }

            $this->imagineCacheManager->remove($pathname, $filters);
        }

        // Create new cached images
        $path = $this->uploaderStorage->resolveUri($image, AbstractImage::PROPERTY_FILE);

        foreach ($filters as $filter) {
            $this->imagineCacheManager->store(
                $this->imagineFilterManager->applyFilter($this->imagineDataManager->find($filter, $path), $filter),
                $path,
                $filter
            );
        }
    }
}


text:
package images

import (
	"fmt"
	"time"

	g "github.com/onsi/ginkgo"
	o "github.com/onsi/gomega"

	kapi "k8s.io/kubernetes/pkg/api"

	exutil "github.com/openshift/origin/test/extended/util"
)

var _ = g.Describe("[images][ruby][Slow] hot deploy for openshift ruby image", func() {
	defer g.GinkgoRecover()
	var (
		railsTemplate = "https://raw.githubusercontent.com/openshift/rails-ex/master/openshift/templates/rails-postgresql.json"
		oc            = exutil.NewCLI("s2i-ruby", exutil.KubeConfigPath())
		modifyCommand = []string{"sed", "-ie", `s%render :file => 'public/index.html'%%`, "app/controllers/welcome_controller.rb"}
		removeCommand = []string{"rm", "-f", "public/index.html"}
		dcName        = "rails-postgresql-example-1"
		dcLabel       = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", dcName))
	)
	g.Describe("Rails example", func() {
		g.It(fmt.Sprintf("should work with hot deploy"), func() {
			oc.SetOutputDir(exutil.TestContext.OutputDir)

			exutil.CheckOpenShiftNamespaceImageStreams(oc)
			g.By(fmt.Sprintf("calling oc new-app -f %q", railsTemplate))
			err := oc.Run("new-app").Args("-f", railsTemplate).Execute()
			o.Expect(err).NotTo(o.HaveOccurred())

			g.By("waiting for build to finish")
			err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), dcName, exutil.CheckBuildSuccessFn, exutil.CheckBuildFailedFn)
			if err != nil {
				exutil.DumpBuildLogs("rails-postgresql-example", oc)
			}
			o.Expect(err).NotTo(o.HaveOccurred())

			// oc.KubeFramework().WaitForAnEndpoint currently will wait forever;  for now, prefacing with our WaitForADeploymentToComplete,
			// which does have a timeout, since in most cases a failure in the service coming up stems from a failed deployment
			err = exutil.WaitForADeploymentToComplete(oc.KubeREST().ReplicationControllers(oc.Namespace()), "rails-postgresql-example", oc)
			o.Expect(err).NotTo(o.HaveOccurred())

			g.By("waiting for endpoint")
			err = oc.KubeFramework().WaitForAnEndpoint("rails-postgresql-example")
			o.Expect(err).NotTo(o.HaveOccurred())

			assertPageContent := func(content string) {
				_, err := exutil.WaitForPods(oc.KubeREST().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunningFn, 1, 2*time.Minute)
				o.Expect(err).NotTo(o.HaveOccurred())

				result, err := CheckPageContains(oc, "rails-postgresql-example", "", content)
				o.Expect(err).NotTo(o.HaveOccurred())
				o.Expect(result).To(o.BeTrue())
			}

			g.By("testing application content")
			assertPageContent("Welcome to your Rails application on OpenShift")
			g.By("modifying the source code with disabled hot deploy")
			RunInPodContainer(oc, dcLabel, modifyCommand)
			RunInPodContainer(oc, dcLabel, removeCommand)
			g.By("testing application content source modification")
			assertPageContent("Welcome to your Rails application on OpenShift")

			pods, err := oc.KubeREST().Pods(oc.Namespace()).List(kapi.ListOptions{LabelSelector: dcLabel})
			o.Expect(err).NotTo(o.HaveOccurred())
			o.Expect(len(pods.Items)).To(o.Equal(1))

			g.By("turning on hot-deploy")
			err = oc.Run("env").Args("rc", dcName, "RAILS_ENV=development").Execute()
			o.Expect(err).NotTo(o.HaveOccurred())
			err = oc.Run("scale").Args("rc", dcName, "--replicas=0").Execute()
			o.Expect(err).NotTo(o.HaveOccurred())
			err = exutil.WaitUntilPodIsGone(oc.KubeREST().Pods(oc.Namespace()), pods.Items[0].Name, 1*time.Minute)
			o.Expect(err).NotTo(o.HaveOccurred())
			err = oc.Run("scale").Args("rc", dcName, "--replicas=1").Execute()
			o.Expect(err).NotTo(o.HaveOccurred())

			g.By("modifying the source code with enabled hot deploy")
			RunInPodContainer(oc, dcLabel, modifyCommand)
			RunInPodContainer(oc, dcLabel, removeCommand)
			assertPageContent("Hello, Rails!")
		})
	})
})


text:
<?php

namespace Ace\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints\DateTime;

/**
 * Post
 *
 * @ORM\Table(name="post")
 * @ORM\Entity
 */
class Post
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="title", type="string", length=255)
     */
    private $title;

    /**
     * @var string
     *
     * @ORM\Column(name="content", type="text")
     */
    private $content;

    /**
     * @var User
     *
     * @Gedmo\Blameable(on="create")
     * @ORM\ManyToOne(targetEntity="User", inversedBy="posts")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     */
    private $user;

    /**
     * @var \DateTime
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(name="created_at", type="datetime")
     */
    private $created_at;

    /**
     * @var array
     *
     * @ORM\OneToMany(targetEntity="Comment", mappedBy="post", cascade="remove")
     */
    private $comments;

    /**
     * __construct
     */
    public function __construct()
    {
        $this->setCreatedAt(new \DateTime());
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set title
     *
     * @param string $title
     * @return Post
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * Get title
     *
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Set content
     *
     * @param string $content
     * @return Post
     */
    public function setContent($content)
    {
        $this->content = $content;

        return $this;
    }

    /**
     * Get content
     *
     * @return string
     */
    public function getContent()
    {
        return $this->content;
    }

    /**
     * @param \Ace\BlogBundle\Entity\User $user
     */
    public function setUser($user)
    {
        $this->user = $user;
    }

    /**
     * @return \Ace\BlogBundle\Entity\User
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * @param \DateTime $created_at
     */
    public function setCreatedAt($created_at)
    {
        $this->created_at = $created_at;
    }

    /**
     * @return \DateTime
     */
    public function getCreatedAt()
    {
        return $this->created_at;
    }

    /**
     * @param array $comments
     */
    public function setComments($comments)
    {
        $this->comments = $comments;
    }

    /**
     * @return array
     */
    public function getComments()
    {
        return $this->comments;
    }

    public function addComment(Comment $comment)
    {
        $this->comments[] = $comment;
    }
}


text:
@interface TextureContent : ContentItem {
	MipmapChainCollection *faces;
}

- (id) initWithFaces:(MipmapChainCollection*)theFaces;

@property (nonatomic, readonly) MipmapChainCollection *faces;

- (void) generateMipmapsAndOverwriteExistingMipmaps:(BOOL)overwriteExistingMipmaps;
- (void) convertBitmapTypeTo:(Class)newBitmapType;
- (void) validate;
- (void) validateWithFacesMustHaveSameMipCount:(BOOL)facesMustHaveSameMipCount;

@end


text:
'use strict'

var test = require('tape')
var http = require('http')
var Buffer = require('safe-buffer').Buffer
var httpHeaders = require('./')

var requestLine = 'GET /foo HTTP/1.1\r\n'
var statusLine = 'HTTP/1.1 200 OK\r\n'
var msgHeaders = 'Date: Tue, 10 Jun 2014 07:29:20 GMT\r\n' +
  'Connection: keep-alive\r\n' +
  'Transfer-Encoding: chunked\r\n' +
  'Age: foo\r\n' +
  'Age: bar\r\n' +
  'Set-Cookie: cookie\r\n' +
  'X-List: A\r\n' +
  'X-Multi-Line-Header: Foo\r\n' +
  ' Bar\r\n' +
  'X-List: B\r\n' +
  '\r\n'
var requestMsg = requestLine + msgHeaders + 'Hello: World'
var responseMsg = statusLine + msgHeaders + 'Hello: World'

var headerResult = {
  date: 'Tue, 10 Jun 2014 07:29:20 GMT',
  connection: 'keep-alive',
  'transfer-encoding': 'chunked',
  age: 'foo',
  'set-cookie': ['cookie'],
  'x-list': 'A, B',
  'x-multi-line-header': 'Foo Bar'
}
var responseResult = {
  version: { major: 1, minor: 1 },
  statusCode: 200,
  statusMessage: 'OK',
  headers: headerResult
}
var requestResult = {
  method: 'GET',
  url: '/foo',
  version: { major: 1, minor: 1 },
  headers: headerResult
}

test('no argument', function (t) {
  t.deepEqual(httpHeaders(), {})
  t.deepEqual(httpHeaders(undefined, true), {})
  t.end()
})

test('empty string', function (t) {
  t.deepEqual(httpHeaders(''), {})
  t.deepEqual(httpHeaders('', true), {})
  t.end()
})

test('empty object', function (t) {
  t.deepEqual(httpHeaders({}), {})
  t.deepEqual(httpHeaders({}, true), {})
  t.end()
})

test('empty buffer', function (t) {
  t.deepEqual(httpHeaders(new Buffer('')), {})
  t.deepEqual(httpHeaders(new Buffer(''), true), {})
  t.end()
})

test('start-line + header', function (t) {
  t.deepEqual(httpHeaders(requestLine + msgHeaders), requestResult)
  t.deepEqual(httpHeaders(statusLine + msgHeaders), responseResult)
  t.deepEqual(httpHeaders(new Buffer(requestLine + msgHeaders)), requestResult)
  t.deepEqual(httpHeaders(new Buffer(statusLine + msgHeaders)), responseResult)
  t.deepEqual(httpHeaders(requestLine + msgHeaders, true), headerResult)
  t.deepEqual(httpHeaders(statusLine + msgHeaders, true), headerResult)
  t.deepEqual(httpHeaders(new Buffer(requestLine + msgHeaders), true), headerResult)
  t.deepEqual(httpHeaders(new Buffer(statusLine + msgHeaders), true), headerResult)
  t.end()
})

test('request-line only', function (t) {
  var requestResult = {
    method: 'GET',
    url: '/foo',
    version: { major: 1, minor: 1 },
    headers: {}
  }

  t.deepEqual(httpHeaders(requestLine + '\r\n'), requestResult)
  t.deepEqual(httpHeaders(new Buffer(requestLine + '\r\n')), requestResult)
  t.deepEqual(httpHeaders(requestLine + '\r\n', true), {})
  t.deepEqual(httpHeaders(new Buffer(requestLine + '\r\n'), true), {})
  t.end()
})

test('status-line only', function (t) {
  var responseResult = {
    version: { major: 1, minor: 1 },
    statusCode: 200,
    statusMessage: 'OK',
    headers: {}
  }

  t.deepEqual(httpHeaders(statusLine + '\r\n'), responseResult)
  t.deepEqual(httpHeaders(new Buffer(statusLine + '\r\n')), responseResult)
  t.deepEqual(httpHeaders(statusLine + '\r\n', true), {})
  t.deepEqual(httpHeaders(new Buffer(statusLine + '\r\n'), true), {})
  t.end()
})

test('headers only', function (t) {
  t.deepEqual(httpHeaders(msgHeaders), headerResult)
  t.deepEqual(httpHeaders(new Buffer(msgHeaders)), headerResult)
  t.deepEqual(httpHeaders(msgHeaders, true), headerResult)
  t.deepEqual(httpHeaders(new Buffer(msgHeaders), true), headerResult)
  t.end()
})

test('full http response', function (t) {
  t.deepEqual(httpHeaders(requestMsg), requestResult)
  t.deepEqual(httpHeaders(responseMsg), responseResult)
  t.deepEqual(httpHeaders(new Buffer(requestMsg)), requestResult)
  t.deepEqual(httpHeaders(new Buffer(responseMsg)), responseResult)
  t.deepEqual(httpHeaders(requestMsg, true), headerResult)
  t.deepEqual(httpHeaders(responseMsg, true), headerResult)
  t.deepEqual(httpHeaders(new Buffer(requestMsg), true), headerResult)
  t.deepEqual(httpHeaders(new Buffer(responseMsg), true), headerResult)
  t.end()
})

test('http.ServerResponse', function (t) {
  t.test('real http.ServerResponse object', function (t) {
    var res = new http.ServerResponse({})
    t.deepEqual(httpHeaders(res), {})
    t.deepEqual(httpHeaders(res, true), {})
    t.end()
  })

  t.test('no _header property', function (t) {
    t.deepEqual(httpHeaders({ _header: undefined }), {})
    t.deepEqual(httpHeaders({ _header: undefined }, true), {})
    t.end()
  })

  t.test('empty string as _header', function (t) {
    t.deepEqual(httpHeaders({ _header: '' }), {})
    t.deepEqual(httpHeaders({ _header: '' }, true), {})
    t.end()
  })

  t.test('normal _header property', function (t) {
    t.deepEqual(httpHeaders({ _header: statusLine + msgHeaders }), responseResult)
    t.deepEqual(httpHeaders({ _header: statusLine + msgHeaders }, true), headerResult)
    t.end()
  })
})

test('set-cookie', function (t) {
  t.deepEqual(httpHeaders('Set-Cookie: foo'), { 'set-cookie': ['foo'] })
  t.deepEqual(httpHeaders('Set-Cookie: foo\r\nSet-Cookie: bar'), { 'set-cookie': ['foo', 'bar'] })
  t.end()
})


text:
package net.sf.jasperreports.engine.fill;

import java.io.IOException;
import java.io.ObjectInputStream;

import net.sf.jasperreports.engine.JRConstants;
import net.sf.jasperreports.engine.JRDefaultStyleProvider;
import net.sf.jasperreports.engine.JRLine;
import net.sf.jasperreports.engine.JROrigin;
import net.sf.jasperreports.engine.base.JRBasePen;
import net.sf.jasperreports.engine.type.LineDirectionEnum;
import net.sf.jasperreports.engine.util.ObjectUtils;

/**
 * Line element information shared by multiple print line objects.
 *
 * @author Teodor Danciu (teodord@users.sourceforge.net)
 * @version $Id: JRTemplateLine.java 7199 2014-08-27 13:58:10Z teodord $
 * @see JRTemplatePrintLine
 */
public class JRTemplateLine extends JRTemplateGraphicElement
{

	/**
	 *
	 */
	private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;

	/**
	 *
	 */
	protected LineDirectionEnum directionValue = LineDirectionEnum.TOP_DOWN;

	/**
	 *
	 */
	protected JRTemplateLine(JROrigin origin, JRDefaultStyleProvider defaultStyleProvider, JRLine line)
	{
		super(origin, defaultStyleProvider);

		setLine(line);
	}

	/**
	 * Creates a template line.
	 *
	 * @param origin the origin of the elements that will use this template
	 * @param defaultStyleProvider the default style provider to use for
	 * this template
	 */
	public JRTemplateLine(JROrigin origin, JRDefaultStyleProvider defaultStyleProvider)
	{
		super(origin, defaultStyleProvider);

		this.linePen = new JRBasePen(this);
	}

	/**
	 *
	 */
	protected void setLine(JRLine line)
	{
		super.setGraphicElement(line);

		setDirection(line.getDirectionValue());
	}

	/**
	 *
	 */
	public LineDirectionEnum getDirectionValue()
	{
		return this.directionValue;
	}

	/**
	 *
	 */
	public void setDirection(LineDirectionEnum directionValue)
	{
		this.directionValue = directionValue;
	}

	/*
	 * These fields are only for serialization backward compatibility.
	 */
	private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID; //NOPMD
	/**
	 * @deprecated
	 */
	private byte direction;

	private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
	{
		in.defaultReadObject();

		if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_7_2)
		{
			directionValue = LineDirectionEnum.getByValue(direction);
		}

	}

	public int getHashCode()
	{
		ObjectUtils.HashCode hash = ObjectUtils.hash();
		addGraphicHash(hash);
		hash.add(directionValue);
		return hash.getHashCode();
	}

	public boolean isIdentical(Object object)
	{
		if (this == object)
		{
			return true;
		}

		if (!(object instanceof JRTemplateLine))
		{
			return false;
		}

		JRTemplateLine template = (JRTemplateLine) object;
		return graphicIdentical(template) && ObjectUtils.equals(directionValue, template.directionValue);
	}

}