summaryrefslogtreecommitdiffstats
path: root/policy-core
diff options
context:
space:
mode:
authorStraubs, Ralph (rs8887) <rs8887@att.com>2019-10-10 07:48:14 -0500
committerStraubs, Ralph (rs8887) <rs8887@att.com>2019-10-15 06:17:37 -0500
commit33ec206449c190cb6fbd5e9ae186b04c15a5576c (patch)
tree8ca5b79c7d304687ee3694452fc0be02fc0c5518 /policy-core
parent464b0e5f62167900d6cf60f058628dc273cedbf0 (diff)
Add 'PolicySession.insertDrools' method
This change includes feature hooks, so a "smart insert" could forward the object to a remote host, and do the insert there. The methods 'insert' and 'insertAll' in 'PolicyContainer' now make use of this smart insert. Change-Id: I69f0e874b6fda09d1f457e4353e4b30d63696210 Issue-ID: POLICY-2160 Signed-off-by: Straubs, Ralph (rs8887) <rs8887@att.com>
Diffstat (limited to 'policy-core')
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java4
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java23
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java15
3 files changed, 40 insertions, 2 deletions
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
index bd97ddb1..4e1b1d6c 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
@@ -489,7 +489,7 @@ public class PolicyContainer implements Startable {
synchronized (sessions) {
PolicySession session = sessions.get(name);
if (session != null) {
- session.getKieSession().insert(object);
+ session.insertDrools(object);
return true;
}
}
@@ -506,7 +506,7 @@ public class PolicyContainer implements Startable {
boolean rval = false;
synchronized (sessions) {
for (PolicySession session : sessions.values()) {
- session.getKieSession().insert(object);
+ session.insertDrools(object);
rval = true;
}
}
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
index 6352eaa2..c2b72fb5 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
@@ -232,6 +232,29 @@ public class PolicySession
}
}
+ /**
+ * This method will insert an object into the Drools memory associated
+ * with this 'PolicySession' instance. Features are given the opportunity
+ * to handle the insert, and a distributed host feature could use this to
+ * send the object to another host, and insert it in the corresponding
+ * Drools session.
+ *
+ * @param object the object to insert in Drools memory
+ */
+ public void insertDrools(Object object) {
+ for (PolicySessionFeatureApi feature :
+ PolicySessionFeatureApiConstants.getImpl().getList()) {
+ if (feature.insertDrools(this, object)) {
+ // feature is performing the insert
+ return;
+ }
+ }
+ // no feature has intervened -- do the insert locally
+ if (kieSession != null) {
+ kieSession.insert(object);
+ }
+ }
+
/*=================================*/
/* 'AgendaEventListener' interface */
/*=================================*/
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java
index dd9ec154..331cebe8 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySessionFeatureApi.java
@@ -78,6 +78,21 @@ public interface PolicySessionFeatureApi extends OrderedService {
}
/**
+ * This method is called when 'PolicySession.insertDrools' is called.
+ * In a distributed host environment, features have the ability to send
+ * the object do a different host, and do the insert.
+ *
+ * @param policySession the 'PolicySession' object associated with the
+ * Drools session
+ * @param object the object to insert in Drools memory
+ * @return 'true' if this feature is handling the operation,
+ * and 'false' if not.
+ */
+ public default boolean insertDrools(PolicySession session, Object object) {
+ return false;
+ }
+
+ /**
* This method is called after 'KieSession.dispose()' is called.
*
* @param policySession the 'PolicySession' object that wrapped the
1 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679