Skip to content

Commit 2a81544

Browse files
authored
PBS-Java module: Added get CPU function (prebid#4900)
* PBS-Java module: Added get CPU function * linting fixes * more linting fixes * more more linting fixes
1 parent 2a93c0a commit 2a81544

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

prebid-server/developers/add-a-module-java.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ title: Prebid Server | Developers | Adding a Java Module
88
# Prebid Server - Adding a Java Module
99
{: .no_toc}
1010

11-
* TOC
11+
- TOC
1212
{:toc }
1313

1414
## Overview
@@ -17,7 +17,7 @@ This document details how to make a module for PBS-Java.
1717

1818
You will want to be familiar with the following background information:
1919

20-
- the [module overview](/prebid-server/developers/add-a-module.html)
20+
- the [module overview](/prebid-server/developers/add-a-module.html)
2121
- the [PBS-Java Modularity Tech Spec](https://docs.google.com/document/d/1VP_pi7L5Iy3ikHMbtC2_rD5RZTVSc3OkTWKvtRS5x5Y/edit#heading=h.oklyk2bogkx4)
2222

2323
### Coding standards
@@ -28,7 +28,7 @@ The module’s code style should correspond to the [PBS-Java project code style]
2828

2929
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:
3030

31-
```
31+
```text
3232
+- prebid-server-java/
3333
+- extra/
3434
+- modules/
@@ -37,13 +37,13 @@ The Prebid Server repository contains a maven submodule called `all-modules` loc
3737
+- pom.xml <- POM of all included modules
3838
```
3939

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.
4141

4242
### Your module's build file
4343

4444
Here's a partial example of your module-specific `pom.xml` file:
4545

46-
```
46+
```text
4747
<?xml ...>
4848
<project ...>
4949
<parent>
@@ -60,6 +60,7 @@ Here's a partial example of your module-specific `pom.xml` file:
6060
```
6161

6262
where:
63+
6364
- 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.
6465
- YOUR_MODULE_ARTIFACT_ID is the name of your module JAR file without version and extension. e.g. ortb2-blocking
6566
- 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:
6869

6970
Add your module within `extra/modules/pom.xml` in the "modules" section:
7071

71-
```
72+
```text
7273
<modules>
7374
...
7475
<module>YOUR_MODULE_ARTIFACT_ID</module>
@@ -79,7 +80,7 @@ Add your module within `extra/modules/pom.xml` in the "modules" section:
7980

8081
The structure of your module source code inside the modules directory must have a standard maven-compatible structure:
8182

82-
```
83+
```text
8384
+- src/
8485
+- main/
8586
+- java/ <- source code
@@ -95,13 +96,15 @@ The structure of your module source code inside the modules directory must have
9596
## Module Code
9697

9798
The quick start is to take a look in two places:
99+
98100
- the [ortb2-blocking module](https://github.com/prebid/prebid-server-java/tree/master/extra/modules/ortb2-blocking)
99101
- the [module test cases](https://github.com/prebid/prebid-server-java/tree/master/src/test/java/org/prebid/server/it/hooks)
100102

101103
### Adding module documentation
104+
102105
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).
103106

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>
105108

106109
### Hook Interfaces
107110

@@ -124,6 +127,7 @@ These are the available hooks that can be implemented in a module:
124127
In a module it is not necessary to implement all mentioned interfaces but only one (or several) required by your functionality.
125128

126129
Each hook interface internally extends org.prebid.server.hooks.v1.Hook basic interface with methods should be implemented:
130+
127131
- `code()` - returns module code.
128132
- `call(...)` - returns result of hook invocation.
129133

@@ -177,7 +181,7 @@ Each hook interface internally extends org.prebid.server.hooks.v1.Hook basic int
177181
);
178182
```
179183

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.
181185

182186
### Applying results asynchronously
183187

@@ -191,6 +195,16 @@ Thus, for any kind of blocking operations it is recommended to use a Vert.x buil
191195

192196
To see how to proceed with async operations, please see similar PBS-Core functionality, for example Currency Conversion Service implementation (class “org.prebid.server.currency.CurrencyConversionService”).
193197

198+
### Available Functions
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+
194208
### Configuration
195209

196210
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
211225

212226
To get analytics tag you need to go into:
213227

214-
```
228+
```text
215229
AuctionEvent
216230
-> AuctionContext
217231
-> HookExecutionContext
@@ -221,11 +235,10 @@ AuctionEvent
221235
-> analyticsTags
222236
```
223237

224-
The AnalyticsTags object has activities with collection of org.prebid.server.hooks.v1.analytics.Result objects inside. Each Result has the values() method which returns com.fasterxml.jackson.databind.node.ObjectNode.
238+
The AnalyticsTags object has activities with collection of org.prebid.server.hooks.v1.analytics.Result objects inside. Each Result has the values() method which returns com.fasterxml.jackson.databind.node.ObjectNode.
225239

226240
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.
227241

228-
229242
## Further Reading
230243

231244
- [PBS Module Overview](/prebid-server/developers/add-a-module.html)

0 commit comments

Comments
 (0)