Skip to content

Commit

Permalink
Prep 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
belgattitude committed Mar 6, 2017
1 parent 467d08e commit c590dca
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- New driver methods: `setFileEncoding()` and `getConnectionOptions()` currently internal use only.
- Support for php-java-bridge 7.
- Possibility to call servlet methods from the driver `$ba->getDriver()->invoke(null, 'myMethod', [$params])`.

### Improved

Expand Down
2 changes: 2 additions & 0 deletions doc/bridge_benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
The following benchmarks does not intend to prove anything but might help understand
the possible overheads when using the bridge. They were designed to illustrate the
cost of creating objects and calling methods (roundtrips).

Be sure to have read the [how it works](./bridge_how_it_works.md) before.

## Simple benchmark

Expand Down
26 changes: 26 additions & 0 deletions doc/bridge_servlet_functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Servlet functions

It's possible to call a specific java servlet function with the `$ba->getDriver()->invoke()`
method. Just ensure the first parameter is null. For a list a functions, refer to
the [JavaBridge class](http://docs.soluble.io/php-java-bridge/api/index.html?io/soluble/pjb/bridge/JavaBridge.html).

## Example

```php

<?php

use Soluble\Japha\Bridge\Adapter as BridgeAdapter;

$ba = new BridgeAdapter([
'driver' => 'Pjb62',
'servlet_address' => 'localhost:8089/servlet.phpjavabridge'
]);

// To get the servlet options in use.
$options = $ba->getDriver()->invoke(null, 'getOptions');

// To set file_encoding
$encoding = $ba->getDriver()->invoke(null, 'setFileEncoding', ['ASCII']);

```
5 changes: 3 additions & 2 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ its target scenarios can be disappointing. In those case,
traditional approaches like REST should be considered and applied instead.

That said, the bridge is a good, reliable and sometimes preferable alternative
over REST for scenarios where a reasonable number of methods calls is intended.

over REST for scenarios where a reasonable number of methods calls is intended
and where you want to keep control of the code on the PHP side.


## Support

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pages:
]
}
- { 'Advanced' : [
{ 'Servlet functions': bridge_servlet_functions.md },
{ 'Servlet session': bridge_servlet_session.md },
{ 'Servlet context': bridge_servlet_context.md }
]}
Expand Down
2 changes: 1 addition & 1 deletion src/Soluble/Japha/Bridge/Driver/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract public function getJavaClass($class_name);
/**
* {@inheritdoc}
*/
abstract public function invoke(Interfaces\JavaType $javaObject, $method, array $args = []);
abstract public function invoke(Interfaces\JavaType $javaObject = null, $method, array $args = []);

/**
* Return Java servlet context.
Expand Down
4 changes: 2 additions & 2 deletions src/Soluble/Japha/Bridge/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public function inspect(Interfaces\JavaObject $javaObject);
/**
* Invoke a method on a JavaObject (or a static method on a JavaClass).
*
* @param Interfaces\JavaType $javaObject javaObject can be Interfaces\JavaClass or Interfaces\JavaObject
* @param Interfaces\JavaType $javaObject javaObject can be Interfaces\JavaClass or Interfaces\JavaObject, if null use servlet methods registered on th JavaBridge side
* @param string $method Method name on the JavaObject or JavaClass
* @param array $args arguments
*
* @return mixed
*/
public function invoke(Interfaces\JavaType $javaObject, $method, array $args = []);
public function invoke(Interfaces\JavaType $javaObject = null, $method, array $args = []);

/**
* Check whether a java value is null.
Expand Down
16 changes: 3 additions & 13 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/Pjb62Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ public function instanciate($class_name, ...$args)
*/
public function setFileEncoding($encoding)
{
try {
$this->pjbProxyClient->invokeMethod(null, 'setFileEncoding', [$encoding]);
} catch (BrokenConnectionException $e) {
PjbProxyClient::getInstance()->destroy();
throw $e;
}
$this->invoke(null, 'setFileEncoding', [$encoding]);
}

/**
Expand All @@ -145,18 +140,13 @@ public function setFileEncoding($encoding)
*/
public function getConnectionOptions()
{
try {
return $this->pjbProxyClient->invokeMethod(null, 'getOptions');
} catch (BrokenConnectionException $e) {
PjbProxyClient::getInstance()->destroy();
throw $e;
}
return $this->invoke(null, 'getOptions');
}

/**
* {@inheritdoc}
*/
public function invoke(Interfaces\JavaType $javaObject, $method, array $args = [])
public function invoke(Interfaces\JavaType $javaObject = null, $method, array $args = [])
{
try {
return $this->pjbProxyClient->invokeMethod($javaObject, $method, $args);
Expand Down
3 changes: 3 additions & 0 deletions test/src/SolubleTest/Japha/Bridge/AdapterUsageCommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public function testJavaHashMap()
{
$ba = $this->adapter;
$hash = $ba->java('java.util.HashMap', ['my_key' => 'my_value']);

$this->assertEquals(1, $hash->size());

$this->assertInstanceOf('Soluble\Japha\Interfaces\JavaObject', $hash);
$this->assertEquals('my_value', $hash->get('my_key'));
$hash->put('new_key', 'oooo');
Expand Down

0 comments on commit c590dca

Please sign in to comment.