# Windows API

## Pre-processor API

Before a window is process the user is able to inject a preprocessing function. The function returns a new window which is subsequently processed by defined window listeners and aggregate functions.

```java
import com.fractalworks.streams.core.data.streams.OrderedStreamEventWindow;
import com.fractalworks.streams.core.data.streams.StreamEvent;
import com.fractalworks.streams.core.data.streams.StreamTimeType;
import com.fractalworks.streams.core.data.streams.Window;
import com.fractalworks.streams.sdk.analytics.WindowPreprocessor;

/**
* Custom preprocessor 
*/
public class MyCustomPreprocessor extends WindowPreprocessor {

    public MyCustomPreprocessor(StreamTimeType streamTimeType, int count, int groupByKey) {
        super(streamTimeType, count, groupByKey);
    }

    public Window compute(Window window) {
        StreamEvent[] orderedEvents = // Do something interesting
        return new OrderedStreamEventWindow(orderedEvents, groupbyKey, streamTimeType);
    }
}

```

## WindowListener API

Custom window listeners can be developed and deployed in to the Joule environment. See [building and deploying custom components](/joule/developer-guides/setting-up-developer-environment/build-and-deploy.md) documentation for further information.

### API

```java
package com.fractalworks.streams.core.listeners;

import com.fractalworks.streams.core.data.Tuple;
import com.fractalworks.streams.core.data.streams.Context;
import com.fractalworks.streams.core.data.streams.Window;

import java.util.Map;

public interface WindowListener {
    Tuple<String, Map<String, Object>> apply(Window window, Context context);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fractalworks.io/joule/developer-guides/builder-sdk/analytics-api/windows-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
