Skip to content

Commit

Permalink
Fixed the bug in the bundle, using a delegated search engine. Added c…
Browse files Browse the repository at this point in the history
…opyrights in classes where it was missing
  • Loading branch information
Tushar-Naik committed May 29, 2022
1 parent 3e862f8 commit b34a787
Show file tree
Hide file tree
Showing 46 changed files with 555 additions and 15 deletions.
2 changes: 1 addition & 1 deletion forage-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>forage</artifactId>
<groupId>com.livetheoogway.forage</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion forage-dropwizard-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>forage</artifactId>
<groupId>com.livetheoogway.forage</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.livetheoogway.forage.dropwizard.bundle;

import com.livetheoogway.forage.models.query.ForageQuery;
import com.livetheoogway.forage.models.result.ForageQueryResult;
import com.livetheoogway.forage.search.engine.ForageSearchEngine;
import com.livetheoogway.forage.search.engine.exception.ForageSearchError;

import java.util.concurrent.atomic.AtomicReference;

public class DelegatedForageSearchEngine<D> implements ForageSearchEngine<D> {
private final AtomicReference<ForageSearchEngine<D>> reference;

public DelegatedForageSearchEngine(ForageSearchEngine<D> preStart) {
this.reference = new AtomicReference<>(preStart);
}

public void onStart(ForageSearchEngine<D> engine) {
reference.set(engine);
}

@Override
public ForageQueryResult<D> search(final ForageQuery query) throws ForageSearchError {
return reference.get().search(query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
import io.dropwizard.ConfiguredBundle;
import io.dropwizard.lifecycle.Managed;
import io.dropwizard.setup.Environment;
import lombok.Getter;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

public abstract class ForageBundle<T extends Configuration, D> implements ConfiguredBundle<T> {

/* the reference to the search engine that you need to use */
@Getter
private ForageSearchEngine<D> searchEngine;
/* the reference to the search engine that will get swapped with the actual one on start up */
private final DelegatedForageSearchEngine<D> delegatedForageSearchEngine
= new DelegatedForageSearchEngine<>(new ForagePreStartEngine<>());

/**
* @param configuration application configuration
Expand All @@ -55,6 +54,10 @@ public abstract class ForageBundle<T extends Configuration, D> implements Config
*/
public abstract ForageConfiguration forageConfiguration(final T configuration);

public ForageSearchEngine<D> searchEngine() {
return delegatedForageSearchEngine;
}

@Override
public void run(final T configuration, final Environment environment) {
AtomicReference<PeriodicUpdateEngine<IndexableDocument>> updateEngineRef = new AtomicReference<>();
Expand All @@ -67,7 +70,7 @@ public void start() {

final ForageEngineIndexer<D> forageEngineIndexer = new ForageEngineIndexer<>(engineBuilder);

searchEngine = forageEngineIndexer;
delegatedForageSearchEngine.onStart(forageEngineIndexer);

final PeriodicUpdateEngine<IndexableDocument> updateEngine = new PeriodicUpdateEngine<>(
bootstrap(configuration),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@

package com.livetheoogway.forage.dropwizard.bundle;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Value;

@Value
public class ForageConfiguration {
/* signifies how often the bootstrap is called */
int refreshIntervalInSeconds;

@JsonCreator
public ForageConfiguration(@JsonProperty("refreshIntervalInSeconds") final int refreshIntervalInSeconds) {
this.refreshIntervalInSeconds = refreshIntervalInSeconds;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.livetheoogway.forage.dropwizard.bundle;

import com.livetheoogway.forage.models.query.ForageQuery;
import com.livetheoogway.forage.models.result.ForageQueryResult;
import com.livetheoogway.forage.search.engine.ForageSearchEngine;
import com.livetheoogway.forage.search.engine.exception.ForageErrorCode;
import com.livetheoogway.forage.search.engine.exception.ForageSearchError;

public class ForagePreStartEngine<D> implements ForageSearchEngine<D> {
@Override
public ForageQueryResult<D> search(final ForageQuery query) throws ForageSearchError {
throw new ForageSearchError(ForageErrorCode.SEARCH_ENGINE_INITIALIZATION_ERROR,
"Forage bundle is not started yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ForageConfiguration forageConfiguration(final SampleConfig configuration)

final ForageSearchError error = Assertions.assertThrows(
ForageSearchError.class,
() -> bundle.getSearchEngine().search(QueryBuilder.matchQuery("author", "rowling").build()));
() -> bundle.searchEngine().search(QueryBuilder.matchQuery("author", "rowling").build()));
Assertions.assertEquals(ForageErrorCode.QUERY_ENGINE_NOT_INITIALIZED_YET, error.getForageErrorCode());

store.put(new Book("id1", "Harry Potter and the Half-Blood Prince", "J.K. Rowling", 4.57f, "eng", 652));
Expand All @@ -106,7 +106,7 @@ public ForageConfiguration forageConfiguration(final SampleConfig configuration)
.pollInterval(Duration.of(100, ChronoUnit.MILLIS))
.until(() -> {
try {
final ForageQueryResult<Book> query2 = bundle.getSearchEngine().search(
final ForageQueryResult<Book> query2 = bundle.searchEngine().search(
QueryBuilder.matchQuery("author", "rowling").build());
return query2.getTotal().getTotal() == 1;
} catch (ForageSearchError e) {
Expand All @@ -116,7 +116,7 @@ public ForageConfiguration forageConfiguration(final SampleConfig configuration)
return false;
}
});
final ForageQueryResult<Book> results = bundle.getSearchEngine().search(
final ForageQueryResult<Book> results = bundle.searchEngine().search(
QueryBuilder.matchQuery("author", "rowling").build());
Assertions.assertEquals("id1", results.getMatchingResults().get(0).getId());
Assertions.assertEquals("Harry Potter and the Half-Blood Prince", results.getMatchingResults()
Expand Down
2 changes: 1 addition & 1 deletion forage-models/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>forage</artifactId>
<groupId>com.livetheoogway.forage</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models;

public interface DataId {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query;

import com.fasterxml.jackson.annotation.JsonSubTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query;

public enum ForageQueryType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query;

@SuppressWarnings("java:S112")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query;

import com.livetheoogway.forage.models.query.search.Query;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query;

import lombok.EqualsAndHashCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query.search;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query.search;

public enum ClauseType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query.search;

public interface ClauseVisitor<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query.search;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query.search;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query.search;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright 2022. Live the Oogway, Tushar Naik
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

package com.livetheoogway.forage.models.query.search;

import com.fasterxml.jackson.annotation.JsonSubTypes;
Expand Down
Loading

0 comments on commit b34a787

Please sign in to comment.