You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: prebid-server/developers/add-a-module-java.md
+25-12Lines changed: 25 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ title: Prebid Server | Developers | Adding a Java Module
8
8
# Prebid Server - Adding a Java Module
9
9
{: .no_toc}
10
10
11
-
* TOC
11
+
- TOC
12
12
{:toc }
13
13
14
14
## Overview
@@ -17,7 +17,7 @@ This document details how to make a module for PBS-Java.
17
17
18
18
You will want to be familiar with the following background information:
19
19
20
-
- the [module overview](/prebid-server/developers/add-a-module.html)
20
+
- the [module overview](/prebid-server/developers/add-a-module.html)
21
21
- the [PBS-Java Modularity Tech Spec](https://docs.google.com/document/d/1VP_pi7L5Iy3ikHMbtC2_rD5RZTVSc3OkTWKvtRS5x5Y/edit#heading=h.oklyk2bogkx4)
22
22
23
23
### Coding standards
@@ -28,7 +28,7 @@ The module’s code style should correspond to the [PBS-Java project code style]
28
28
29
29
The Prebid Server repository contains a maven submodule called `all-modules` located in the `extra/modules` folder. It includes all available PBS modules. So, in order to add a new module, fork the repository and create a folder with the desired name inside the modules folder with the following structure:
30
30
31
-
```
31
+
```text
32
32
+- prebid-server-java/
33
33
+- extra/
34
34
+- modules/
@@ -37,13 +37,13 @@ The Prebid Server repository contains a maven submodule called `all-modules` loc
37
37
+- pom.xml <- POM of all included modules
38
38
```
39
39
40
-
A benefit of open sourcing your module in this way is that it can use the parent `all-modules` as a maven dependency. It simplifies management of the PBS-Core and other commonly used dependencies and you will be confident that it works well with the current version of Prebid Server.
40
+
A benefit of open sourcing your module in this way is that it can use the parent `all-modules` as a maven dependency. It simplifies management of the PBS-Core and other commonly used dependencies and you will be confident that it works well with the current version of Prebid Server.
41
41
42
42
### Your module's build file
43
43
44
44
Here's a partial example of your module-specific `pom.xml` file:
45
45
46
-
```
46
+
```text
47
47
<?xml ...>
48
48
<project ...>
49
49
<parent>
@@ -60,6 +60,7 @@ Here's a partial example of your module-specific `pom.xml` file:
60
60
```
61
61
62
62
where:
63
+
63
64
- PREBID_SERVER_VERSION is the current version of Prebid Server. The release team will update this value for all modules with each release, but you need to set it to the version of PBS that you're developing with.
64
65
- YOUR_MODULE_ARTIFACT_ID is the name of your module JAR file without version and extension. e.g. ortb2-blocking
65
66
- YOUR_MODULE_TEXTUAL_NAME is unique within the space of all other modules. e.g. instead of naming a module "blocking", a better name would be "ortb2blocking".
@@ -68,7 +69,7 @@ where:
68
69
69
70
Add your module within `extra/modules/pom.xml` in the "modules" section:
70
71
71
-
```
72
+
```text
72
73
<modules>
73
74
...
74
75
<module>YOUR_MODULE_ARTIFACT_ID</module>
@@ -79,7 +80,7 @@ Add your module within `extra/modules/pom.xml` in the "modules" section:
79
80
80
81
The structure of your module source code inside the modules directory must have a standard maven-compatible structure:
81
82
82
-
```
83
+
```text
83
84
+- src/
84
85
+- main/
85
86
+- java/ <- source code
@@ -95,13 +96,15 @@ The structure of your module source code inside the modules directory must have
95
96
## Module Code
96
97
97
98
The quick start is to take a look in two places:
99
+
98
100
- the [ortb2-blocking module](https://github.com/prebid/prebid-server-java/tree/master/extra/modules/ortb2-blocking)
99
101
- the [module test cases](https://github.com/prebid/prebid-server-java/tree/master/src/test/java/org/prebid/server/it/hooks)
100
102
101
103
### Adding module documentation
104
+
102
105
It is required to add a "README.md" file to the root of your module folder. Recommended this file contains the description of what the implemented module does, links to external documentation and includes maintainer contact info (email, slack, etc).
103
106
104
-
The documentation must also live on the docs.prebid.org site. Please add a markdown file to https://github.com/prebid/prebid.github.io/tree/master/prebid-server/pbs-modules
107
+
The documentation must also live on the docs.prebid.org site. Please add a markdown file to <https://github.com/prebid/prebid.github.io/tree/master/prebid-server/pbs-modules>
105
108
106
109
### Hook Interfaces
107
110
@@ -124,6 +127,7 @@ These are the available hooks that can be implemented in a module:
124
127
In a module it is not necessary to implement all mentioned interfaces but only one (or several) required by your functionality.
125
128
126
129
Each hook interface internally extends org.prebid.server.hooks.v1.Hook basic interface with methods should be implemented:
130
+
127
131
-`code()` - returns module code.
128
132
-`call(...)` - returns result of hook invocation.
129
133
@@ -177,7 +181,7 @@ Each hook interface internally extends org.prebid.server.hooks.v1.Hook basic int
177
181
);
178
182
```
179
183
180
-
More test implementations for each hook can be found in unit-tests at https://github.com/prebid/prebid-server-java/tree/master/src/test/java/org/prebid/server/it/hooks folder.
184
+
More test implementations for each hook can be found in unit-tests at <https://github.com/prebid/prebid-server-java/tree/master/src/test/java/org/prebid/server/it/hooks> folder.
181
185
182
186
### Applying results asynchronously
183
187
@@ -191,6 +195,16 @@ Thus, for any kind of blocking operations it is recommended to use a Vert.x buil
191
195
192
196
To see how to proceed with async operations, please see similar PBS-Core functionality, for example CurrencyConversionService implementation (class “org.prebid.server.currency.CurrencyConversionService”).
193
197
198
+
### AvailableFunctions
199
+
200
+
#### Getting the localhost CPU
201
+
202
+
To support modules that need to obtain information about the local CPU environment (e.g. a traffic-shaping), the code can call this function:
203
+
204
+
```java
205
+
cpuLoadAverageStats.getCpuLoadAverage(); // returns a float
206
+
```
207
+
194
208
### Configuration
195
209
196
210
It's possible to define default module configuration which can be read by the module at PBS startup. Please see the [Configuration](https://docs.google.com/document/d/1VP_pi7L5Iy3ikHMbtC2_rD5RZTVSc3OkTWKvtRS5x5Y/edit#heading=h.mh3urph3k1mk) section of the technical specification.
@@ -211,7 +225,7 @@ Analytics adapters can receive these tags in a parameter that's been added to th
211
225
212
226
To get analytics tag you need to go into:
213
227
214
-
```
228
+
```text
215
229
AuctionEvent
216
230
->AuctionContext
217
231
->HookExecutionContext
@@ -221,11 +235,10 @@ AuctionEvent
221
235
-> analyticsTags
222
236
```
223
237
224
-
TheAnalyticsTags object has activities with collection of org.prebid.server.hooks.v1.analytics.Result objects inside. EachResult has the values() method which returns com.fasterxml.jackson.databind.node.ObjectNode.
238
+
TheAnalyticsTags object has activities with collection of org.prebid.server.hooks.v1.analytics.Result objects inside. EachResult has the values() method which returns com.fasterxml.jackson.databind.node.ObjectNode.
225
239
226
240
It depends on the particular module implementation how to parse their analytics tags, since the internal structure is custom and depends on the module. Therefore, analytics modules that want to report on specific behavior need to be coded to know about that module. See the ortb2blocking module for an example of what analytics tags may be available.
0 commit comments